Definition
The array_fill_keys() function fills an array with values, specifying keys.
Syntax
array_fill_keys(keys, value)
Parameters
Parameter | Description |
---|---|
keys |
Required. Array of values that will be used as keys. |
value |
Required. Specifies the value to use for filling the array. |
Example
<?php
$keys = array("foo", "bar", "baz");
$result = array_fill_keys($keys, "hello");
print_r($result);
echo "<br>";
$keys = range(1, 6);
$result = array_fill_keys($keys, "hello");
print_r($result);
echo "<br>";