PHP array_fill_keys() Function
It fills an array with the value of the value parameter, using the values of the keys array as keys.
The function array_fill() is used to assign or fill mixed values to an array by declaring suitable number of elements in the array. Whereas the function array_fill_keys() is used to fill mixed values to an array corresponding to the key values.
Parameter | Description |
---|---|
keys | Required. Array of values that will be used as keys |
value | Required. Specifies the value to use for filling the array |
Syntax
array_fill_keys(keys,value);
Example
$keys=array("a","b","c","d");
$array=array_fill_keys($keys,"Prince");
print_r($array);
Output
Array ( [a] => Prince [b] => Prince [c] => Prince [d] => Prince )
Leave a Reply