Home >> PHP >> array_merge_recursive() function in PHP

array_merge_recursive() function in PHP

The array_merge_recursive() function used for merges one or more arrays recursively.

Syntax

array_merge_recursive(array1,array2,array3...)

Example 1

$array1=array("ram","shyam");
$array2=array("ghanshyam","ravi");
print_r(array_merge_recursive($array1,$array2));

Output

Array ( [0] => ram [1] => shyam [2] => ghanshyam [3] => ravi )

Example 2

$array1=array("a"=>"ram","b"=>"shyam");
$array2=array("c"=>"ghanshyam","b"=>"ravi");
print_r(array_merge_recursive($array1,$array2));

Output

Array ( [a] => ram [b] => Array ( [0] => shyam [1] => ravi ) [c] => ghanshyam )

Post Your Comment

Next Questions
array_multisort() function
array_pad() function
array_pop() function
array_product() function
array_push() function
array_rand() function
array_reduce() function
array_reverse() function
array_search() function
array_shift() function
array_slice() function
array_splice() function
array_sum() function
array_udiff() function
array_udiff_assoc() function
array_udiff_uassoc() function
array_uintersect() function
array_uintersect_assoc() function
array_uintersect_uassoc() function
array_unique() function
array_unshift() function
array_values() function
array_walk() function
array_walk_recursive() function
asort() function

Copyright ©2022 coderraj.com. All Rights Reserved.