PHP array_merge_recursive() Function
Definition
The array_merge_recursive() function merges one ore more arrays into one array. array_merge_recursive() function makes the values as an array for duplicated keys.
If there is no duplicates the array_merge_recursive() function will behave the same as the array_merge() function.
Syntax
PHP array_merge_recursive() Function has the following syntax.
array_merge_recursive(array1,array2,array3...)
Parameter
Parameter | Is Required | Description |
---|---|---|
array1 | Required. | Array to merge |
array2 | Optional. | Array to merge |
array3,... | Optional. | Array to merge |
Example
Merge two array recursively
<?php/*w w w . j ava 2 s . com*/
$a1=array("a"=>"A","b"=>"B","j"=>"java2s.com");
$a2=array("c"=>"C","B"=>"b");
print_r(array_merge_recursive($a1,$a2));
?>
The code above generates the following result.