PHP array_merge_recursive()Functions
Complete PHP Array Reference Manual
Examples
Merge two arrays into one array:
<?php
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge_recursive($a1,$a2));
?>
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge_recursive($a1,$a2));
?>
Run Example »
Definition and Usage
The array_merge_recursive() function is used to merge one or more arrays into one array.
The difference between this function andarray_merge()the function lies in handling cases where two or more array elements have the same key name. array_merge_recursive() does not overwrite key names, but instead recursively forms the values of multiple identical key names into an array.
Note:If you pass only one array to the array_merge_recursive() function, the result isarray_merge()the same, and the function returns a new array with integer keys, whose keys are re-indexed starting from 0.
Syntax
array_merge_recursive(array1,array2,array3...)
| Parameter | Description |
|---|---|
| array1 | Required. Specifies an array. |
| array2 | Optional. Specifies an array. |
| array3 | Optional. Specifies an array. |
Technical Details
| Return value: | Returns the merged array. |
|---|---|
| PHP Version: | 4.0.1+ |
Complete PHP Array Reference Manual Other Extensions