Populate an array with values, using specified keys:
<?php $keys=array(“a”,“b”,“c”,“d”); $a1=array_fill_keys($keys,“blue”); print_r($a1); ?> |
The array_fill_keys()
function populates an array with values based on specified keys.
array_fill_keys(keys, value) |
Parameter |
Description |
keys |
Required. An array of values to be used as keys. |
value |
Required. Specifies the value to use for populating the array. |
Return Value: |
Returns the populated array. |
PHP Version: |
5.2+ |