I have the following code
$teste1 = array(
1 => array( 1 => 'teste1', 2 => 'teste2', 3 => 'teste3'),
2 => array(3 => 'teste4', 5 => 'teste5')
);
$teste2 = array(
1 => array( 3 => 'teste6', 4 => 'teste7')
);
function uniqKeys($arr1, $arr2){
if(empty($arr1)){
return $arr2;
}
foreach ($arr1 as $key1 => $value1) {
foreach ($arr2 as $key2 => $value2) {
if ($key2 == $key1) {
foreach($value2 as $key3 => $value3) {
array_push($arr1[$key1], $value3);
}
}
}
}
return $arr1;
}
print_r(uniqKeys($teste1, $teste2));
result
Array
(
[1] => Array
(
[1] => teste1
[2] => teste2
[3] => teste3
[4] => teste6
[5] => teste7
)
[2] => Array
(
[3] => teste4
[5] => teste5
)
)
I would like to know if there is a cleaner way to do this join, I did a traditional looping, but as they are too much data, it will require a lot of the server.