超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<array_multisortarray_pop>
Last updated: Fri, 22 Jun 2007

array_pad

(PHP 4 , PHP 5)

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

说明

array array_pad ( array input, int pad_size, mixed pad_value)

array_pad() 返回 input 的一个拷贝,并用 pad_value 将其填补到 pad_size 指定的长度。如果 pad_size 为正,则数组被填补到右侧,如果为负则从左侧开始填补。如果 pad_size 的绝对值小于或等于 input 数组的长度则没有任何填补。

例子 1. array_pad() 例子

<?php
$input
= array (12, 10, 9);

$result = array_pad ($input, 5, 0);
// result is array (12, 10, 9, 0, 0)

$result = array_pad ($input, -7, -1);
// result is array (-1, -1, -1, -1, 12, 10, 9)

$result = array_pad ($input, 2, "noop");
// not padded
?>

参见 array_fill()range()




add a note add a note User Contributed Notes
array_pad
ethanhunt314 at hotmail dot com
10-Dec-2000 08:25
This is useful when using next() and prev() function in a while loop to traverse an array.

For example the following code will only output up to 8.

<?php
$test[] = "1";
$test[] = "2";
$test[] = "3";
$test[] = "4";
$test[] = "5";
$test[] = "6";
$test[] = "7";
$test[] = "8";
$test[] = "9";
$test[] = "10";
$test[] = " ";
$test[] = " ";
$test[] = " ";

$count = count($test);

while($i < $count) {

$now = current($test);
echo "

$now

";

next($test);
next($test);
next($test);
prev($test);
prev($test);
prev($test);


$i++;
next($test);
}
?>

But if you use:
$test = array_pad($test, 13, " ");

you will get all of your output.

<array_multisortarray_pop>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22