English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP array_fill_keys() Function Usage and Example

PHP Array Function Manual

array_fill_keys — Fill an array with specified keys and values

Syntax

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

Definition and usage

It useskeysThe values of the array are used as keys withvalueFill the array with parameter values.

Parameter

NumberParameters and descriptions
1

keys

It is the array of values used as keys

2

value

It can be a string or a value array

Return value

It returns a filled array

Online example

<?php
   $ = array('f1',' 5, 10, 'b1);
   $a = array_fill_keys($input, 'banana');
   
   print_r($a)
?>
Test to see ‹/›

Output result:

Array (
   [f1] => banana
   [5] => banana
   [10] => banana
   [b1] => banana
)

PHP Array Function Manual