Example
Fill the array with the key value of the given specified key name:
<?php $keys=array("a","b","c","d"); $a1=array_fill_keys($keys,"blue"); print_r($a1); ?>
Definition and usage
array_fill_keys() Function Fills the array with the key value of the given specified key name.
Syntax
array_fill_keys(keys,value);
Parameters | Description |
keys | Required. Array whose values will be used to populate the array keys. |
value | Required. Specifies the key values used to populate the array. |
Technical Details
Return value: | Returns the populated array. |
PHP version: | 5.2+ |
Example:
<?php $keys = array('foo', 5, 10, 'bar'); $a = array_fill_keys($keys, 'banana'); print_r($a); ?>
The running results are as follows :
Array( [foo] => banana [5] => banana [10] => banana [bar] => banana )
The above is the detailed content of The function array_fill_keys() that fills the array with the key value of the specified key name given by php. For more information, please follow other related articles on the PHP Chinese website!