Definition
The array_fill() function fills an array with values.
Syntax
array_fill(index, number, value)
Parameters
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. |
Example
<?php
$array1 = array_fill(1, 5, "apple");
print_r($array1);
echo "<br>";
$array2 = array_fill(-2, 6, "banana");
print_r($array2);
echo "<br>";