合并两个数组的方法

通过foreach循环来合并数组

代码:

1

2

3

4

5

6

7

8

9

<?php

    $a = array(array("1","2"),array("3","4"));

    $b = array(array("a","b"),array("c","d")); 

     

    foreach($a as $key=>$vo){

        $list[] = array_merge($vo,$b[$key]);

    }

     

    print_r($list);

结果:

        

foreach($curve1_list as $key=>$vo){

$data[] = array_merge(['curvel' => $vo],['curve2' => $curve2_list[$key]]);

}



var_dump($data);die;
$data = [
'curvel' =>$curve1_list,
'curve2' =>$curve2_list,
];

// $data = [
// [
// 'curve1' => [
// 'time' => '2018-09-12 14:42:00',
// 'date' => '1000',
// ],
// 'curve2' => [
// 'time' => '2018-10-12 14:42:00',
// 'date' => '900',
// ],
// ],
// [
// 'curve1' => [
// 'time' => '2018-09-20 14:42:05',
// 'date' => '1300',
// ],
// 'curve2' => [
// 'time' => '2018-10-20 14:42:05',
// 'date' => '1000',
// ],
// ],
// [
// 'curve1' => [
// 'time' => '2018-09-12 14:42:10',
// 'date' => '1500',
// ],
// 'curve2' => [
// 'time' => '2018-10-12 14:42:10',
// 'date' => '1300',
// ],
// ],
// [
// 'curve1' => [
// 'time' => '2018-09-23 14:42:15',
// 'date' => '1800',
// ],
// 'curve2' => [
// 'time' => '2018-10-23 14:42:15',
// 'date' => '1500',
// ],
// ],
// [
// 'curve1' => [
// 'time' => '2018-09-12 14:42:20',
// 'date' => '2200',
// ],
// 'curve2' => [
// 'time' => '2018-10-12 14:42:20',
// 'date' => '1200',
// ],
// ],
// ];
posted on 2018-11-25 19:21  zxyPhp  阅读(527)  评论(0编辑  收藏  举报