PHP array_fill_keys() Function

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

ParameterDescriptionIs compulsory
KeysIt is an array of values that will be used as keys.compulsory
ValuesIt 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 ) )