Untitled


SUBMITTED BY: Guest

DATE: Nov. 17, 2013, 4:34 p.m.

FORMAT: Text only

SIZE: 1.8 kB

HITS: 9261

  1. [
  2. {
  3. Name0: "TEST",
  4. Value0: "13",
  5. Timestamp0: "2012-01-02 00:00:13"
  6. },
  7. {
  8. Name0: "TEST",
  9. Value0: "16",
  10. Timestamp0: "2012-01-02 00:10:45"
  11. }
  12. ],
  13. [
  14. {
  15. Name1: "TEST",
  16. Value1: "30",
  17. Timestamp1: "2012-01-02 00:00:13"
  18. },
  19. {
  20. Name1: "TEST",
  21. Value1: "60",
  22. Timestamp1: "2012-01-02 00:10:45"
  23. }
  24. ]
  25. [
  26. {
  27. Name0: "TEST",
  28. Value0: "13",
  29. Timestamp0: "2012-01-02 00:00:13",
  30. Name1: "TEST",
  31. Value1: "30",
  32. Timestamp1: "2012-01-02 00:00:13"
  33. },
  34. {
  35. Name0: "TEST",
  36. Value0: "16",
  37. Timestamp0: "2012-01-02 00:10:45",
  38. Name1: "TEST",
  39. Value1: "60",
  40. Timestamp1: "2012-01-02 00:10:45"
  41. }
  42. ]
  43. $loop_length = count($array[0]);
  44. $new_array = array();
  45. for($i=0; $i<$loop_length; $i++){
  46. for($j=0; $j<count($array); $j++){
  47. if(!array_key_exists($j,$new_array)) $new_array[$j] = array();
  48. $new_array[$j] = array_merge($new_array[$j],$array[$i][$j]);
  49. }
  50. }
  51. var_dump($new_array);
  52. <?php
  53. for ($i = 0; $i < count($array[0]); $i++) {
  54. $array[0][$i] = array_merge($array[0][$i], $array[1][$i]);
  55. }
  56. $array = $array[0];
  57. ?>
  58. <?php
  59. $arr1 = array(array('name0' => 'foo', 'val0' => '10'),
  60. array('name0' => 'cde', 'val0' => '11'));
  61. $arr2 = array(array('name1' => 'bar', 'val1' => '20'),
  62. array('name1' => 'fgh', 'val0' => '21'));
  63. $arr_mrg = array();
  64. for($i=0; $i<count($arr1); $i++){
  65. $arr_mrg[$i] = array_merge($arr1[$i], $arr2[$i]);
  66. }
  67. var_dump($arr_mrg); //test output of the result
  68. ?>

comments powered by Disqus