note 111001 modified in function.array-fill-keys by danbrown
| From: | danbrown@php.net | Date: | Thu, 17 Jan 2013 15:24:48 +0000 |
| Subject: | note 111001 modified in function.array-fill-keys by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-193145@lists.php.net to get a copy of this message | ||
If an associative array is used as the second parameter of array_fill_keys, then the associative
array will be appended in all the values of the first array.
e.g.
<?php
$array1 = array(
"a" => "first",
"b" => "second",
"c" => "something",
"red"
);
$array2 = array(
"a" => "first",
"b" => "something",
"letsc"
);
print_r(array_fill_keys($array1, $array2));
?>
The output will be
Array(
[first] => Array(
[a] => first,
[b] => something,
[0] => letsc
),
[second] => Array(
[a] => first,
[b] => something,
[0] => letsc
),
[something] => Array(
[a] => first,
[b] => something,
[0] => letsc
),
[red] => Array(
[a] => first,
[b] => something,
[0] => letsc
)
)
--was--
If an associative array is used as the second parameter of array_fill_keys, then the associative
array will be appended in all the values of the first array.
e.g.
$array1 = array(
"a" => "first",
"b" => "second",
"c" => "something",
"red"
);
$array2 = array(
"a" => "first",
"b" => "something",
"letsc"
);
print_r(array_fill_keys($array1, $array2));
// The output will be
Array(
[first] => Array(
[a] => first,
[b] => something,
[0] => letsc
),
[second] => Array(
[a] => first,
[b] => something,
[0] => letsc
),
[something] => Array(
[a] => first,
[b] => something,
[0] => letsc
),
[red] => Array(
[a] => first,
[b] => something,
[0] => letsc
)
)
http://php.net/manual/en/function.array-fill-keys.php