array_merge_recursive
Merge one or more arrays recursively
The array_merge_recursive()
function combines one or more arrays into an array.
The difference between this function and array_merge()
function is that when two or more array elements have the same key name. array_merge_recursive()
does not overwrite key names, but recursively combines multiple values of the same key names into an array.
Note: If you just enter an array to the array_merge_recursive()
function and the result is the same as array_merge()
, the function returns a new array with integer key names whose key names start with 0.
Combine two arrays into an array:
<?php $a1 = array ( "a" => "red" , "b" => "green" ) ; $a2 = array ( "c" => "blue" , "b" => "yellow" ) ; print_r ( array_merge_recursive ( $a1 , $a2 ) ) ; ?>
Try it yourself
array_merge_recursive ( array1 , array2 , array3 ... )
parameter | describe |
---|---|
array1 | Required. Specify array. |
array2 | Optional. Specify array. |
array3 | Optional. Specify array. |