PHP 4 >= 4.2.0, PHP 5, PHP 7, PHP 8
array_fill - Fill an array with values

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

Fills an array with count entries of the value of the value parameter, keys starting at the start_index parameter.



The first index of the returned array.

If start_index is negative, the first index of the returned array will be start_index and the following indices will start from zero (see example).


Number of elements to insert. Must be greater than or equal to zero.


Value to use for filling

Return Values

Returns the filled array

Exceptions and Errors

Throws a E_WARNING if count is less than zero.


See also the Arrays section of manual for a detailed explanation of negative keys.

Related Functions

Example of array_fill

Show all examples for array_fill

PHP Version:

Function array_fill:

Arrays Functions

Most used PHP functions