PHP array_fill_keys() Function
Last Updated : 17 Mar 2025
The array_fill_keys( ) function is a built-in function in PHP. It is used to create a new array filled with the given keys and value provided as an array to the function. It was introduced in PHP version 5.2.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| Keys | It is an array of values that will be used as keys. | compulsory |
| Values | It may a string or an array of values. | compulsory |
Return Type
It returns the filled array.
EXAMPLE 1
Output:
Array ( [a] => javatpoint [b] => javatpoint [c] => javatpoint [d] => javatpoint )
EXAMPLE 2
Output:
Array ( [1] => 1000 [2] => 1000 [3] => 1000 [4] => 1000 [5] => 1000 [apple] => 1000 )
EXAMPLE 3
Output:
Array ( [Delhi] => lndia [Haryana] => lndia [Bihar] => lndia [Gujarat] => lndia )
EXAMPLE 4
Output:
Array ( [Delhi] => Array ( [0] => india [1] => javatpoint ) [Haryana] => Array ( [0] => india [1] => javatpoint ) [Bihar] => Array ( [0] => india [1] => javatpoint ) [Gujarat] => Array ( [0] => india [1] => javatpoint ) )
Next TopicPhp-array-filter-function