美文网首页
【函数分享】每日PHP函数分享(2021-2-27)

【函数分享】每日PHP函数分享(2021-2-27)

作者: 梦中程序员 | 来源:发表于2021-02-26 11:01 被阅读0次

array_fill — 用给定的值填充数组

说明

array_fill ( int $start_index , int $count , mixed $value ) : array
用 value 参数的值填充 count 个元素到数组, 开始键名由 start_index 参数指定。

参数

start_index:返回的数组的第一个索引值。如果 start_index 是负数, 那么返回的数组的第一个索引将会是 start_index ,而后面索引则从0开始。、

count:要插入元素的数量。必须大于或等于 0。

value:用来填充的值。

返回值

返回填充后的数组。

错误/异常

如果 count 小于零,将会抛出 E_WARNING。

范例

<?php
$a = array_fill(5, 6, 'banana');
$b = array_fill(-2, 4, 'pear');
print_r($a);
print_r($b);
?>

输出
Array
(
    [5]  => banana
    [6]  => banana
    [7]  => banana
    [8]  => banana
    [9]  => banana
    [10] => banana
)
Array
(
    [-2] => pear
    [0] => pear
    [1] => pear
    [2] => pear
)

相关文章

网友评论

      本文标题:【函数分享】每日PHP函数分享(2021-2-27)

      本文链接:https://www.haomeiwen.com/subject/kfgbfltx.html