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, and returns the resulting array eg.

<?php
$array1 = array("color" => "red", 2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>

The above example will output:

Array
(
    [color] => green
    [0] => 2
    [1] => 4
    [2] => a
    [3] => b
    [shape] => trapezoid
    [4] => 4
)

Note "color" => "red" is overwritten by "color" => "green".

Reference

Leave a Reply

Your email address will not be published. Required fields are marked *