PHP array_fill() Function
The array_fill() function is used to fill an array with values.
The function fills an array with num entries of the value of the array_values parameter, keys starting at the starting_index parameter.
you can see below there Parameters and Descriptions.
Parameter | Description |
---|---|
index | Required. The first index of the returned array |
number | Required. Specifies the number of elements to insert |
value | Required. Specifies the value to use for filling the array |
Syntax
array_fill(index,number,value);
Example
$array1 = array_fill(3,6,"James");
$array2 = array_fill(0,2,"Cooper");
print_r($array1);
echo "<br>";
print_r($array2);
Output
Array ( [3] => James [4] => James [5] => James [6] => James [7] => James [8] => James )
Array ( [0] => Cooper [1] => Cooper )
Leave a Reply