array_fill_keys() function in php
0 2020
array_fill_keys() function of PHP is used to fill an array with values by defining the keys of array. It is an inbuilt function of PHP.
Syntax:
array_fill_keys ($key,$arr_value);
Here
- $key is an user define array which elements used by function as array keys.
- $arr_value represents the value of array elements.
Example:
<?php $key=array("fruit1","fruit2","fruit3","fruit4","fruit5","fruit6"); $value="Mango"; $arr1=array_fill_keys($key,$value); echo "<pre>"; print_r($arr1); ?>
Output:

Share:
Comments
Waiting for your comments