Jump to: navigation, search

Php array fill keys

From w3cyberlearnings

Contents

PHP function array_fill_keys

This function returns a new array fill with values.

Syntax array_fill_keys

  • array: array key
  • value: value to fill
array_fill_keys(array, value);

Note

Priod to PHP 5 >= 5.2.0 only. You can use another array function to complete the same thing.

Example 1


<?php

$person = array('bob', 'janny', 'marry');

$new_person = array_fill_keys($person, "person");
print_r($new_person);
?>

Output

Array
(
    [bob] => person
    [janny] => person
    [marry] => person
)

Related Links


Navigation
Web
SQL
MISC
References