fork download
  1. <?php
  2.  
  3. $array1 = array(
  4. '2013-05-01' => 'test',
  5. '2013-05-02' => 'testing',
  6. '2013-05-03' => 'working',
  7. '2013-05-04' => 'future test'
  8. );
  9.  
  10. $array2 = array(
  11. '2013-05-01' => '1',
  12. '2013-05-02' => 'done',
  13. '2013-05-03' => 'code',
  14. '2013-05-05' => 'release'
  15. );
  16.  
  17. function merge_array() {
  18. $merged = array();
  19. $arrays = func_get_args();
  20.  
  21. if ($arrays) {
  22. foreach ($arrays as $array) {
  23. foreach ($array as $key => $value) {
  24. if (isset($merged[$key])) {
  25. $merged[$key] .= ' ' . $value;
  26. }
  27. else {
  28. $merged[$key] = $value;
  29. }
  30. }
  31. }
  32. }
  33.  
  34. return $merged;
  35. }
  36.  
  37. $result = merge_array($array1, $array2);
  38. print_r($result);
  39. ?>
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [2013-05-01] => test 1
    [2013-05-02] => testing done
    [2013-05-03] => working code
    [2013-05-04] => future test
    [2013-05-05] => release
)