Combine 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));?>The array_merge_recursive() function is used to merge one or more arrays into one array.
The difference between this function and the array_merge() function is that it handles the case where two or more array elements have the same key name. array_merge_recursive() does not perform key name overwriting, but recursively combines multiple values with the same key name into an array.
Note: If you simply feed an array to the array_merge_recursive() function, the result is the same as array_merge(), which returns a new array with integer keys that are re-indexed starting at 0.
array_merge_recursive( array1,array2,array3... )
| parameter | describe |
|---|---|
| array1 | Required. Specifies an array. |
| array2 | Optional. Specifies an array. |
| array3 | Optional. Specifies an array. |
| Return value: | Returns the merged array. |
|---|---|
| PHP version: | 4.0.1+ |