PHP provides you with a solution to solve this common problem:
$a = array_merge($b, $c);
With this solution, you take all the elements inside $ b and combine them with $ c. But if you use associative arrays, you should notice that you replace the values ββin $ b with the numbers in $ c.
For instance:
<?php $a = array( 'ka' => 1, 'kb' => 1, ); $b = array( 'kb' => 2, 'kc' => 2, ); print_r(array_merge($a, $b)); ?>
The result of this code will be something like:
Array ( [ka] => 1 [kb] => 2 [kc] => 2 )
source share