Array_fill – Fills the array with the given values

instructions

array_fill ( int $start_index , int $count , mixed $value ) : array
Copy the code

Fill the array with the value of the value argument. The start key is specified by the start_index argument.

parameter

Start_index: the first index value of the returned array. If start_index is negative, the first index of the returned array will be start_index, with subsequent indexes starting at 0. ,

Count: Number of elements to be inserted. Must be greater than or equal to 0.

Value: the value used for padding.

The return value

Returns the populated array.

** Error/exception **

If count is less than zero, E_WARNING is raised.

sample

<? php $a = array_fill(5, 6, 'banana'); $b = array_fill(-2, 4, 'pear'); print_r($a); print_r($b); ? > Output Array([5] => banana [6] => banana [7] => banana [8] => banana [9] => banana [10] => banana) Array([-2] => Pear [0] => pear [1] => pear [2] => pear )Copy the code