PHP

PHP Menu

PHP

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

Definition

The array_merge() function merges one or more arrays into one array.

Syntax

array_merge(array1, array2, array3, ...)

Parameters

Parameter Description
array1 Required. Specifies an array.
array2 Optional. Specifies the second array to merge.
array3... Optional. Specifies more arrays to merge.

Example

<?php
// Example 1 $cities = array("New York", "Salt Lake", "Tokyo"); $cities2 = array("Berlin", "London", "Munich"); print_r(array_merge($cities, $cities2)); echo "<br>";
// Example 2 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); $ages2 = array("Alex"=>23, "Rey"=>21, "Ivan"=>18); print_r(array_merge($ages, $ages2)); echo "<br>";
// Example 3 $ages = array("Mark" => 22, "Jeff" => 32, "Mike" => 28); print_r(array_merge($ages)); echo "<br>";

Introduction

PHP Basics

PHP Advance

PHP OOP

PHP Functions and Methods