PHP Tutorial PHP Advanced PHP Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

PHP - Array array_fill() Function



The PHP Array array_fill() function returns an array filled with specified value with specified number of times and the index of the array starts from specified index.

Syntax

array_fill(start_index, count, value)

Parameters

start_index Required. Specify the staring index of the returned array.
count Required. Specify the number of elements inserted.
value Required. Specify the value to be inserted.

Return Value

Returns the filled array.

Exceptions

throws E_WARNING, if count is less than zero.

Example:

The example below shows the usage of array_fill() function.

<?php
$Arr = array_fill(10, 5, "A");

print_r($Arr);
?>

The output of the above code will be:

Array
(
    [10] => A
    [11] => A
    [12] => A
    [13] => A
    [14] => A
)

❮ PHP Array functions

5