English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The PHP array_merge_recursive() function recursively merges one or more arrays
array array_merge_recursive( array $array1 [, array $array2...] )
The array_merge_recursive() function merges the elements of one or more arrays together, appending the values of one array to the end of the previous array. It returns the resulting array.
If the input array contains the same string key name, these values will be merged into an array, which will be recursive. Therefore, if a value itself is an array, this function will merge it into another array according to the corresponding entry. It should be noted that if the array has the same numeric key name, the latter value will not overwrite the original value but will be appended to the end.
Serial Number | Parameters and Description |
---|---|
1 | array1(Required) It specifies an array. |
2 | array2(Optional) It specifies an array. |
It returns the resulting array.
It merges the elements of two arrays together and appends the values of one array to the end of the previous array.
<?php $input1 = array("a" => "Horse", "b" => "Cat", "c" => "Dog"); $input2 = array("d" => "Cow", "a" => "Cat", "e" => "elephant"); print_r(array_merge_recursive($input1$input2)); ?>Test and See‹/›
Output Result:
Array ( [a] => Array ( [0] => Horse [1] => Cat ) [b] => Cat [c] => Dog [d] => Cow [e] => elephant )