How to use array merge recursive in PHP

In this article, I will explain how the array_merge_recursive() function can be used in PHP.
  • 1853

array_merge_recursive() function in PHP

  • The array_merge_recursive() function merges one ore more arrays into one array.

  • In array_merge_recursive() function, the elements of one are appended to the end of the previous one.

  • The array_merge_recursive() function will behave exactly the same as the array_merge() function. If you assign only one array to the array_merge_recursive() function,

Syntax

array_merge_recursive(array1,array2,array3....)

Parameter

  • array1 array1 is required parameter. determine the array name.

  • array2 array2 is optional parameter. determine the array name.

  • array3 array3 is optional parameter. specifies an array name.

Example

The following example show to how the array_merge_recursive() function can be used in PHP.

<html>

<body>

<h3 style="color: saddlebrown;">array_merge_recursive() function example in PHP</h3>

    <?php

    $a1=array('a'=>"Nitin","Sachin"=>"Ravi");

    $a2=array("c"=>"Saurabh","b"=>"Arvind");

    print_r(array_merge_recursive($a1,$a2));

    ?>

</body>

</html>

 

Output

 merge-recursive.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.