fork(1) download
  1. <?php
  2.  
  3. $teste1 = array(
  4. 1 => array( 1 => 'teste1', 2 => 'teste2', 3 => 'teste3'),
  5. 2 => array(3 => 'teste4', 5 => 'teste5')
  6. );
  7.  
  8. $teste2 = array(
  9. 1 => array( 3 => 'teste6', 4 => 'teste7')
  10. );
  11.  
  12. function uniqKeys($arr1, $arr2)
  13. {
  14. foreach($arr2 as $key => $value)
  15. {
  16. $arr1[$key] = array_key_exists($key, $arr1) ? array_merge($arr1[$key], $value) : $value;
  17. }
  18.  
  19. return $arr1;
  20. }
  21.  
  22. print_r(uniqKeys($teste1, $teste2));
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [1] => Array
        (
            [0] => teste1
            [1] => teste2
            [2] => teste3
            [3] => teste6
            [4] => teste7
        )

    [2] => Array
        (
            [3] => teste4
            [5] => teste5
        )

)