-2

I have two arrays:

$array1 = array(
  'currencies' => array(
    'dollars' => array(80,120,75),
    'euro' => array(25,35,10,85),
  ),
);

$array2 = array(
  'currencies' => array(
    'dollars' => array(25),
  ),
);

I would like the result to be:

$result = array(
  'currencies' => array(
    'dollars' => array(80,120,75,25),
    'euro' => array(25,35,10,85),
  ),
);

Can this be accomplished in a clever way? I have tried array_merge, array_merge_recursively etc.

tolborg
  • 612
  • 4
  • 21
  • I guess this question may help: http://stackoverflow.com/questions/2140503/how-to-merge-subarray-in-php-most-easily – Nelson Teixeira Apr 22 '16 at 16:49
  • Did you try [array_merge_recursive()](https://secure.php.net/manual/ru/function.array-merge-recursive.php)? This is not what you want? – Andrew Apr 22 '16 at 16:51
  • did you really try `array_merge_recursively()`? https://3v4l.org/AkeFu – IROEGBU Apr 22 '16 at 16:51

1 Answers1

5

how did you try with array_merge_recursive? Because this works good for me:

<?php
$array1 = array(
  'currencies' => array(
    'dollars' => array(80,120,75),
    'euro' => array(25,35,10,85),
  ),
);

$array2 = array(
  'currencies' => array(
    'dollars' => array(25),
  ),
);

var_dump(array_merge_recursive($array1, $array2));
Jojo
  • 2,720
  • 1
  • 17
  • 24