Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PHP array_merge_recursive() Function

PHP array_merge_recursive() Function

PHP Array ReferenceComplete PHP Array Reference Manual

Example

Merge two arrays into one array:

"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 merges one or more arrays into one array.

The difference between this function and array_merge() is how it handles two or more array elements with the same key. array_merge_recursive() does not overwrite keys; instead, it recursively combines the values of identical keys into an array.

**Note:** If you pass only one array to array_merge_recursive(), the result is the same as array_merge() , and the function returns a new array with integer keys reindexed starting from 0.


Syntax

array_merge_recursive(

array1,array2,array3...

)

Parameters Description
array1 Required. Specifies the array.
array2 Optional. Specifies an array.
array3 Optional. Specifies an array.

Technical Details

Return Value: Returns the merged array.
PHP Version: 4.0.1+

PHP Array ReferenceComplete PHP Array Reference Manual