PHP - Function array_merge_recursive()



array array_merge_recursive ( array $array1 [, array $array2...] )

Definition and Usage

Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one.

If the input arrays have the same string keys, then the values for these keys are merged together into an array, and this is done recursively, so that if one of the values is an array itself, the function will merge it with a corresponding entry in another array too.


Parameter Description
array1 Required. Specifies an array.
array2 Optional. Specifies an array.

Return Values

It returns the resulting array.


Try out following example −


This will produce the following result −

Array ( [a] => Array ( [0] => Horse [1] => Cat ) [b] => Cat [c] => Dog [d] => Cow [e] => elephant )