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.
PHP array_merge_recursive() Function has the following syntax.
array_merge_recursive(array1,array2,array3...)
Parameter | Is Required | Description |
---|---|---|
array1 | Required. | Array to merge |
array2 | Optional. | Array to merge |
array3,... | Optional. | Array to merge |
Merge two array recursively
<?php
$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.