• PHP Video Tutorials

PHP - Function array_fill_keys()



Syntax

array array_fill_keys ( array $keys, mixed $value );

Definition and Usage

It fills an array with the value of the value parameter, using the values of the keys array as keys.

Parameters

Sr.No Parameter & Description
1

keys

It is an array of values that will be used as keys

2

value

It may an string or an array of values

Return Values

It returns the filled array

Example

Try out following example −

<?php
   $ = array('f1', 5, 10, 'b1');
   $a = array_fill_keys($input, 'banana');
   
   print_r($a)
?> 

This will produce the following result −

Array (
   [f1] => banana
   [5] => banana
   [10] => banana
   [b1] => banana
)
php_function_reference.htm
Advertisements