PHP-array_ fill

Array Fill as the name suggests is used to fill out the Indices of an Array with values. All you have to do is specify the starting Index, the ending Index and the value that you want to fill out the array with.

The syntax goes something like this-

array_fill ( int $start_index , int $end_index ,  $value );
For Example-
This means that you filling the Indices 2,3 and 4 with 25
If you print the array, this would be the output
    [2]  => 25
    [3]  => 25
    [4]  => 25

One could also use this function to Initialize multi dimensional arrays. For example- this is how one would Initialize a 2-Dimensional Array

  $a array_fill(010array_fill(0100));


It is a 10×10 array and all the values are Initialized to 0.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s