1
2<?php
3$array1 = array("color" => "red", 2, 4);
4$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
5$result = array_merge($array1, $array2);
6print_r($result);
7?>
8Array
9(
10 [color] => green
11 [0] => 2
12 [1] => 4
13 [2] => a
14 [3] => b
15 [shape] => trapezoid
16 [4] => 4
17)
18
1<?php
2 $array1 = [
3 "color" => "green"
4 ];
5 $array2 = [
6 "color" => "red",
7 "color" => "blue"
8 ];
9 $result = array_merge($array1, $array2);
10?>
11
12// $result
13[
14 "color" => "green"
15 "color" => "red",
16 "color" => "blue"
17]
1<?php
2
3$array1 = array('key1' => 'test1', 'key2' => 'test2');
4$array2 = array('key3' => 'test3', 'key4' => 'test4');
5
6$resultArray = array_merge($array1, $array2);
7
8// If you have numeric or numeric like keys, array_merge will
9// reset the keys to 0 and start numbering from there
10
11$resultArray = $array1 + $array2;
12
13// Using the addition operator will allow you to preserve your keys,
14// however any duplicate keys will be ignored.