Php Array Function array_fill_keys()

What is array_fill_keys() Function?

Explanation

The "array_fill_keys()" function is used fill an array with values,by specifying the keys.

Syntax:


array_fill_keys(array,value)

In the above syntax "array" is the array to be filled with the values provided in "value".

Example :


<?php
$b = array('food', 5, 10, 'bar');
$a = array_fill_keys($b, 'fruit');
print_r($a);
?>
Result :

Array
(
[food]=> fruit
[5]
=> fruit
[10] => fruit
[bar] => fruit
)

In the above example array is filled for the specified keys. The keys are food, 5, 10, bar, are filled with the string 'fruit'.

PHP Topics


Ask Questions

Ask Question