fork(1) download
  1. <?php
  2.  
  3. function mesclar(array $arrX, array $arrY)
  4. {
  5. $z = array();
  6. $chaves = array_merge( array_keys($arrX), array_keys($arrY) ); //Pega as chaves de ambas arrays
  7.  
  8. foreach ($chaves as $chave)
  9. {
  10. if (isset($z[$chave]) === false) {
  11. $z[$chave] = array();
  12. }
  13.  
  14. if (array_key_exists($chave, $arrX))
  15. {
  16. $z[$chave]['X'] = $arrX[ $chave ];
  17. }
  18.  
  19. if (array_key_exists($chave, $arrY))
  20. {
  21. $z[$chave]['Y'] = $arrY[ $chave ];
  22. }
  23. }
  24.  
  25. return $z;
  26. }
  27.  
  28. $arX = array('AAA' => 173.696, 'BBB' => 72.436, 'CCC' => 142.692);
  29. $arY = array('AAA' => 127, 'DDD' => 72.333);
  30.  
  31. $novaArray = mesclar($arX, $arY);
  32.  
  33. print_r( $novaArray );
Success #stdin #stdout 0.01s 23916KB
stdin
Standard input is empty
stdout
Array
(
    [AAA] => Array
        (
            [X] => 173.696
            [Y] => 127
        )

    [BBB] => Array
        (
            [X] => 72.436
        )

    [CCC] => Array
        (
            [X] => 142.692
        )

    [DDD] => Array
        (
            [Y] => 72.333
        )

)