Fill an array with values, specifying keys in PHP

Description

The following code shows how to fill an array with values, specifying keys.

Example


/*from  www  .j a  v  a  2  s. com*/
<?php
    $keys=array("a","b","c","d");
    $a1=array_fill_keys($keys,"blue");
    print_r($a1);
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Data Types »




Array
Array Associative
Array Util
ArrayObject
Data Types
Date
Date Format
DateTime
Number
String
String Escape
String Filter
String HTML
String Type
Timezone