array_fill_keys() function in php || PHP Functions

array_fill_keys() function in php

Last Updated by Pooja Chikara 29-Mar-20

0 256


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

  1. $key is an user define array which elements used by function as array keys.
  2. $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:

array_fill_keys() function in php


Share:


Leave a Reply


Comments
    Waiting for your comments