Merging arrays in php

array_merge Merges the elements of one or more arrays together so that the values of one are appended to the end of the previous one. It returns the resulting array.

Syntax

array array_merge ( array $array1 [, array $... ] )

Example

<?php
$array1 = array(2,22,33,56,21,27);
$array2 = array(3,2,88,9,6,12,32);
$result = array_merge($array1, $array2);
var_dump($result);
?>

Output

array (size=13)
  0 => int 2
  1 => int 22
  2 => int 33
  3 => int 56
  4 => int 21
  5 => int 27
  6 => int 3
  7 => int 2
  8 => int 88
  9 => int 9
  10 => int 6
  11 => int 12
  12 => int 32
Share

You may also like...