PHP array_fill() Function

Example

Fill an array with values:

<?php
$a1=array_fill(3,4,"blue");
print_r($a1);
?>

Running Example

Definition and Usage

The array_fill() function fills the array with key-value pairs.

Description

The array_fill() function fills the array with the given value, and the returned array has number elements, with values of value. The returned array uses numeric indexing, starting from start Starting from the position and incrementing. If number Would result in an error if 0 or less.

Syntax

array_fill(index,number,value);
Parameter Description
index Required. Specifies the first index of the returned array.
number Required. Specifies the number of elements to be inserted.
value Required. Specifies the values to be used to fill the array.

Technical Details

Return Value: Returns the filled array.
PHP Version: 4.2+