PHP array_merge_recursive() Function

Definition

The array_merge_recursive() function merges one ore more arrays into one array. array_merge_recursive() function makes the values as an array for duplicated keys.

If there is no duplicates the array_merge_recursive() function will behave the same as the array_merge() function.

Syntax

PHP array_merge_recursive() Function has the following syntax.

array_merge_recursive(array1,array2,array3...)

Parameter

ParameterIs RequiredDescription
array1Required.Array to merge
array2Optional.Array to merge
array3,...Optional.Array to merge

Example

Merge two array recursively


<?php/*w  w w  . j ava  2 s . com*/
    $a1=array("a"=>"A","b"=>"B","j"=>"java2s.com");
    $a2=array("c"=>"C","B"=>"b");
    print_r(array_merge_recursive($a1,$a2));
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions