PHP array_merge_recursive() Function
Last Updated : 17 Mar 2025
The array_merge_recursive( ) function is a built-in function in PHP. This function is used to merge the elements or values of two or more arrays together into a single array, the values of one are appended to the end of the previous one. This function was introduced in PHP 4.0.1.
Syntax
Parameter
| Parameter | Description | Is compulsory |
|---|---|---|
| array1 | Specifies an array. | compulsory |
| array2 | Specifies an array. | Optional |
| array3,... | Specifies an array. | Optional |
Return Type
An array of values resulted from merging the arguments together.
EXAMPLE 1
Output:
Array ( [a] => sachin [b] => Array ( [0] => virat [1] => ganguly ) [c] => yuvraj )
EXAMPLE 2
Output:
Array ( [a] => java [b] => T [z] => point [d] => tutorial )
EXAMPLE 3
Output:
Array ( [A] => Black [B] => Array ( [0] => Green [1] => Almond ) [C] => Yellow [D] => Array ( [0] => White [1] => Coconut ) [E] => Cyan [F] => Aero [H] => Blood [J] => Dark brown )
EXAMPLE 4
Output:
Array ( [a] => Array ( [0] => yuvraj [1] => sachin ) [b] => sachin [c] => rahul [d] => umesh [e] => ganguly )
Next TopicPhp-array-multisort-function