php-Arrays函数-array_pad-用值将数组填补到指定长度_PHP教程

WBOY
Release: 2016-07-13 17:51:09
Original
1078 people have browsed it

array_pad() 用值将数组填补到指定长度

【功能】
         该函数将返回指定数组的一个复制,并用指定的值将其填补到指定的长度。
         如果指定长度为正,则数组被填补到右侧,如果为负则从左侧开始填补。
         如果指定长度的绝对值小于或等于原数组的长度,则没有任何填补
         有可能一次最多填补1048576个数组元素
【使用范围】
         php4、php5.
【使用】
         array array_pad( array input,int pad_size,mixed pad_value  )
         input/必需/原数组
         pad_size/必需/要填补的指定长度
         pad_value/必需/为指定的值
【示例】
[php]
$input=array(12,10,9); 
var_dump( array_pad($input,5,0) ); 
var_dump( array_pad($input,-7,-1) ); 
var_dump( array_pad($input,2,"noop") ); 
/*
array(5) {
  [0]=>
  int(12)
  [1]=>
  int(10)
  [2]=>
  int(9)
  [3]=>
  int(0)
  [4]=>
  int(0)
}
array(7) {
  [0]=>
  int(-1)
  [1]=>
  int(-1)
  [2]=>
  int(-1)
  [3]=>
  int(-1)
  [4]=>
  int(12)
  [5]=>
  int(10)
  [6]=>
  int(9)
}
array(3) {
  [0]=>
  int(12)
  [1]=>
  int(10)
  [2]=>
  int(9)
}
*/ 

 


摘自 zuodefeng的笔记

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478218.htmlTechArticlearray_pad() 用值将数组填补到指定长度 【功能】 该函数将返回指定数组的一个复制,并用指定的值将其填补到指定的长度。 如果指定长度为...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!