码迷,mamicode.com
首页 > 编程语言 > 详细

php 合并数组的方法 非array_merge

时间:2016-01-10 07:04:25      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

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语句合并成了一个结果

php 合并数组的方法 非array_merge

标签:

原文地址:http://www.cnblogs.com/hellowzd/p/5117701.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!