当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > array_pad() 函数

PHP
PHP Libxml
PHP Math
PHP Misc
PHP MySQL
PHP SimpleXML
PHP String
PHP XML
PHP Zip
PHP Mail
用PHP5的DirectoryIterators递归扫描目录
PHP 阻止SQL注入式攻击
PHP5面向对象 - 基础 - 类和对象
PHP5面向对象 - 基础 - 类的属性( public )
PHP5面向对象 - 基础 - 类的属性( private )
PHP5面向对象 - 基础 - 方法
PHP5面向对象 - 基础 - 对象的比较
php5面向对象 - 基础 - 构造函数
php5面向对象 - 基础 - 析构函数
用PHP控制用户的浏览器 - ob*函数的使用
PHP PDO 学习笔记

PHP 中的 array_pad() 函数


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-03-04   浏览: 489 ::
收藏到网摘: n/a

Definition and Usage
定义和用法

The array_pad() function inserts a specified number of elements, with a specified value, to an array.
array_pad()函数向指定的数组中插入指定数量的项,并给每个项附上指定的值。

Syntax
语法

array_pad(array,size,value)

Parameter参数 Description描述
array Required. Specifies an array
必要参数。指定一个数组
size Required. Specifies the number of elements in the array returned from the function
必要参数。指定从函数中返回的数组元素数量(即:对这些元素的数量进行限定)
value Required. Specifies the value of the new elements in the array returned from the function
必要参数。指定从函数中返回的数组元素


Tips and Notes
提示和注意

Tip: If you assign a negative size parameter, the function will insert new elements BEFORE the original elements. (See example 2)
提示:如果你给size参数指定一个负数,这个函数将在原始元素之前插入新元素。(见案例2)

Note: This function will not delete any elements if the size parameter is less than the original array's size.
注意:如果size参数小于原始数组的size参数,那么函数将不会删除任何元素。


Example 1
案例1

<?php
$a=array("Dog","Cat");
print_r(array_pad($a,5,0));
?>

The output of the code above will be:
上述代码将产生下面的结果:

Array ( [0] => Dog [1] => Cat [2] => 0 [3] => 0 [4] => 0 )


Example 2
案例2

With a negative size parameter:
Size参数为负数:

<?php
$a=array("Dog","Cat");
print_r(array_pad($a,-5,0));
?>

The output of the code above will be:
上述代码将输出下面的结果:

Array ( [0] => 0 [1] => 0 [2] => 0 [3] => Dog [4] => Cat )

评论 (0) All

登陆 | 还没注册?