• PHP Video Tutorials

PHP - Function array_merge_recursive()



Syntax

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

Definition and Usage

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

Parameters

Sr.No Parameter & Description
1

array1(Required)

It specifies an array.

2

array2(Optional)

It specifies an array.

Return Values

It returns the resulting array.

Example

Try out following example −

<?php
   $input1 = array("a"=>"Horse","b"=>"Cat","c"=>"Dog");
   $input2 = array("d"=>"Cow","a"=>"Cat","e"=>"elephant");
   
   print_r(array_merge_recursive($input1,$input2));
?> 

This will produce the following result −

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