array_merge_recursive
array array_merge_recursive(mixed value_1, mixed value_2, mixed ...)
|
value_1
|
Base array or value
|
|
value_2
|
Next value or array to merge
|
|
...
|
Further values or arrays to be merged
|
Recursively merges all passed values into one array.
Returns:
Array containing the results of merging all passed values; NULL on failure
Description:
This function is like array_merge() except that identically-keyed nested arrays are recursed through and merged with each other, just as though array_merge() had been called on them.
Version:
PHP 4 since 4.0.1
See also:
array_merge()
Example:
Recursively merge arrays
$ax = array("a" => "alpha", "b" => "bravo",
"z" => array("c" => "charlie", "d" => "delta"));
$ay = array("t" => "tango", "u" => "uniform", "v" => "victor",
"z" => array("w" => "whiskey", "x" => "x-ray"));
$az = array("lima", "mike", "november",
"not_z" => array("Bill" => "Cat", "Rosebud" => "basselope"));
print_r(array_merge_recursive($ax, $ay, $az));
Output:
Array
(
[a] => alpha
[b] => bravo
[z] => Array
(
[c] => charlie
[d] => delta
[w] => whiskey
[x] => x-ray
)
[t] => tango
[u] => uniform
[v] => victor
[0] => lima
[1] => mike
[2] => november
[not_z] => Array
(
[Bill] => Cat
[Rosebud] => basselope
)
)
|