Instance
Fills an array with the given key value:
<?php$a1=array_fill (3,4, "blue");p Rint_r ($a 1);? >
Definition and usage
The Array_fill () function fills an array with the given key value.
Grammar
Array_fill (Index,number,value);
| parameters |
description |
| index |
required. Specifies the starting index of the returned array. |
| number |
required. Specifies the number of elements to fill, whose value must be greater than 0. |
| value |
required. Specifies the key value used to populate the array. |
Technical details
| return value: |
Returns an array of fills. |
| PHP version: |
4.2+ |
Example
<?php $a =array_fill (2,3, "Dog"); Print_r ($a);?>
Output:
Array ([2] = dog [3] = dog [4] = dog)
The following statements can be used to populate:
$abc =0;for ($i =0; $i <3; $i + +) {for ($j =0; $j <2; $j + +) {$abc = $abc +1; $creation [$i] [$j]= $abc;}}
The result is:
Array ([0] = = Array ([0] = 1 [1] = 2) [1] = = Array ([0] = = 3 [1] = 4) [2] = = Array ([0] = = 5 [1] = 6))