PHP array_fill_keys() function fill an array with values

Definition

The array_fill_keys() function fills an array with values for specified keys.

Syntax

PHP array_fill_keys() function has the following syntax.

array_fill_keys(keys,value);

Parameter

ParameterIs RequiredDescription
keysRequired.Key Array
valueRequired.Specifies the value to use for filling the array

Example

Fill an array with values, specifying keys:


<?php//  ww w.  j a va 2 s. co m
$keys=array("a","b","c","d","j");
$a1=array_fill_keys($keys,"java2s.com");
print_r($a1);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions