PHP

PHP Menu

PHP

array_merge_recursive() Function - Definition, Syntax, Parameters, Examples

Definition

The array_merge_recursive() function merges one or more arrays into one array recursively. It merges the elements of one or more arrays together in such a way that the values of one are appended to the end of the previous one, and returns a new array with merged elements.

Syntax

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

Parameters

Parameter Description
array1 Required. Specifies an array.
array2 Optional. Specifies an array.
array3 Optional. Specifies an array.

Example

<?php
// Example 1 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); $ages2 = array("Alex"=>23, "Rey"=>21, "Ivan"=>18); print_r(array_merge_recursive($ages, $ages2)); echo "<br>";
// Example 2 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); $ages2 = array("Alex"=>23, "Jeff" => 32, "Ivan"=>18); print_r(array_merge_recursive($ages, $ages2)); echo "<br>";
// Example 3 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); print_r(array_merge_recursive($ages)); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods