PHP Tutorial - 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
$keys=array("a","b","c","d","j");
$a1=array_fill_keys($keys,"java2s.com");
print_r($a1);
?>

The code above generates the following result.