array_fill_keys in PHP

Syntax of array_fill_keys in PHP

array array_fill_keys(array keys, mixed value)

Returns an array containing values for each item in keys, using the elements in keys for each element’s key and value for each element’s value

Example of array_fill_keys

$keys = array('foo', 5, 10, 'bar');
$a = array_fill_keys($keys, 'banana');
    [foo] => banana
    [5] => banana
    [10] => banana
    [bar] => banana

Leave a Comment