Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_fill_keys()

Example

Populate an array with values, using specified keys:

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

Definition and Usage

The array_fill_keys() function populates an array with values based on specified keys.

Syntax

array_fill_keys(keys, value)

Parameter Values

Parameter

Description

keys

Required. An array of values to be used as keys.

value

Required. Specifies the value to use for populating the array.

Technical Details

Return Value:

Returns the populated array.

PHP Version:

5.2+