php add 2 arrays code example
Example 1: php merge 2 arrays
<?php
$array1 = [
"color" => "green"
];
$array2 = [
"color" => "red",
"color" => "blue"
];
$result = array_merge($array1, $array2);
?>
[
"color" => "green"
"color" => "red",
"color" => "blue"
]
Example 2: php array merge for associative arrays
<?php
$array1 = array('key1' => 'test1', 'key2' => 'test2');
$array2 = array('key3' => 'test3', 'key4' => 'test4');
$resultArray = array_merge($array1, $array2);
$resultArray = $array1 + $array2;
Example 3: php combine values of two arrays
$all_arrays = array_merge($array1, $array2, $array3, ...);