To join two arrays in a new array
in PHP, we can do it through the array_merge
function or through the sum operator ( +
).
In this case we have two examples:
$a = ['stack' => 'overflow'];
$b = ['oveflow' => 'stack'];
$c = array_merge($a, $b); //
$d = $a + $b;
print_r($c); // Array ( [stack] => overflow [oveflow] => stack )
print_r($d); // Array ( [stack] => overflow [oveflow] => stack )
What are the main differences between these two ways of joining arrays
?