array_fill_keys

(PHP 5 >= 5.2.0, PHP 7, PHP 8)

array_fill_keysFill an array with values, specifying keys

Опис

array_fill_keys(array $keys, mixed $value): array

Fills an array with the value of the value parameter, using the values of the keys array as keys.

Параметри

keys

Array of values that will be used as keys. Illegal values for key will be converted to string.

value

Value to use for filling

Значення, що повертаються

Returns the filled array

Приклади

Приклад #1 array_fill_keys() example

<?php
$keys
= array('foo', 5, 10, 'bar');
$a = array_fill_keys($keys, 'banana');
print_r($a);
?>

Поданий вище приклад виведе:

Array
(
    [foo] => banana
    [5] => banana
    [10] => banana
    [bar] => banana
)

Прогляньте також