The array_fill_keys() function fills an array with values for specified keys.
PHP array_fill_keys() function has the following syntax.
array_fill_keys(keys,value);
Parameter | Is Required | Description |
---|---|---|
keys | Required. | Key Array |
value | Required. | Specifies the value to use for filling the array |
Fill an array with values, specifying keys:
<?php
$keys=array("a","b","c","d","j");
$a1=array_fill_keys($keys,"java2s.com");
print_r($a1);
?>
The code above generates the following result.