php 合并数组的方法 非array_merge

Array
(
    [0] => Array
        (
            [max] => 50
            [date] => 2016-01-07
        )

    [1] => Array
        (
            [max] => 100
            [date] => 2016-01-08
        )

)
Array
(
    [0] => Array
        (
            [min] => 11
            [date] => 2016-01-07
        )

    [1] => Array
        (
            [min] => 11
            [date] => 2016-01-08
        )

)
Array
(
    [0] => Array
        (
            [price] => 11
            [date] => 2016-01-07
        )

    [1] => Array
        (
            [price] => 100
            [date] => 2016-01-08
        )

)
Array
(
    [0] => Array
        (
            [price] => 50
            [date] => 2016-01-07
        )

    [1] => Array
        (
            [price] => 11
            [date] => 2016-01-08
        )

)

方法

$i=-1;
        foreach($list2 as $key=>$value){
            $i++;
            //echo $i;
            //echo $value['min'];
            $list1[$i]['min']=$value['min'];
        }
        
        $i=-1;
        foreach($list3 as $key=>$value){
            $i++;
            //echo $i;
            //echo $value['min'];
            $list1[$i]['start']=$value['price'];
        }
        
        $i=-1;
        foreach($list4 as $key=>$value){
            $i++;
            //echo $i;
            //echo $value['min'];
            $list1[$i]['end']=$value['price'];
            $list1[$i]['date']=$value['date'];
        }
        
        //$list1['0']['min']="123";
        //$list1['1']['min']="456";
        print_r ($list1);

结果

Array
(
    [0] => Array
        (
            [max] => 50
            [min] => 11
            [start] => 11
            [end] => 50
            [date] => 2016-01-07
        )

    [1] => Array
        (
            [max] => 100
            [min] => 11
            [start] => 100
            [end] => 11
            [date] => 2016-01-08
        )

)

相当于四条sql语句合并成了一个结果

posted @ 2016-01-10 02:05  fleam  阅读(295)  评论(0编辑  收藏  举报