Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

array_merge_recursive()

Example

Combine two arrays into a single array:

<?php
$a1=array(“a”=>“red”,“b”=>“green”);
$a2=array(“c”=>“blue”,“b”=>“yellow”);
print_r(array_merge_recursive($a1,$a2));
?>

Definition and Usage

The array_merge_recursive() function combines one or more arrays into a single array.

Unlike array_merge(), which overrides values for duplicate keys, array_merge_recursive() merges values into an array if the keys are the same.

 

Note: When only one array is passed to array_merge_recursive(), it behaves the same as array_merge().

Syntax

array_merge_recursive(array1, array2, array3, …)

Parameter Values

 

Parameter

Description

array1

Required. Defines an array.

array2

Optional. Provides an array.

array3,…

Optional. Indicates an array.

Technical Details

Return Value:

Returns the combined array.

PHP Version:

4.0.1+