PHP array_merge_recursive() Functions
Example
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)); ?>
Definition and Usage
The array_merge_recursive() function merges one or more arrays into one array.
This function is similar to array_merge() The difference between the functions lies in the handling of the same key names for two or more array elements. array_merge_recursive() does not perform key name overlay, but recursively combines multiple values with the same key name into an array.
Note:If you only input an array into the array_merge_recursive() function, the result is the same as array_merge(), and the function will return a new array with integer keys, re-indexing starting from 0.
Syntax
array_merge_recursive(array1,array2,array3...)
Parameters | Description |
---|---|
array1 | Required. Specify an array. |
array2 | Optional. Specify an array. |
array3 | Optional. Specify an array. |
Technical Details
Return Value: | Returns the merged array. |
PHP Version: | 4.0.1+ |