PHP

PHP Menu

PHP

array_fill_keys() Function - Definition, Syntax, Parameters, Examples

Definition

The array_fill_keys() function fills an array with values, specifying keys.

Syntax

array_fill_keys(keys, value)

Parameters

Parameter Description
keys Required. Array of values that will be used as keys.
value Required. Specifies the value to use for filling the array.

Example

<?php
$keys = array("foo", "bar", "baz"); $result = array_fill_keys($keys, "hello"); print_r($result); echo "<br>";
$keys = range(1, 6); $result = array_fill_keys($keys, "hello"); print_r($result); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods