PHP array_fill_keys() Function

Example

Fill an array with specified keys and values:

<?php
$keys=array("a","b","c","d");
$a1=array_fill_keys($keys,"blue");
print_r($a1);
?>

Run Instance

Definition and Usage

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

Syntax

array_fill_keys(keys,value);
Parameters Description
keys Required. Use the values of the array as keys. Illegal values will be converted to strings.
value Required. The values used to fill the array.

Technical Details

Return Value: Returns the filled array.
PHP Version: 5.2+