Current Location: Home> Function Categories> array_fill

array_fill

Fill the array with the given value
Name:array_fill
Category:Array
Programming Language:php
One-line Description:Fill the array with the given key value.

Definition and usage

array_fill() function fills the array with key values.

illustrate

array_fill() function fills the array with the given value. The returned array has number elements and the value is value . The returned array uses a numeric index, starting from the start position and incrementing. If number is 0 or less than 0, an error occurs.

Example

Fill the array with values:

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

Try it yourself

grammar

 array_fill ( index , number , value ) ;
parameter describe
index Required. The first index of the array is returned.
number Required. Specifies the number of elements to be inserted.
value Required. Specifies the value used to fill the array.