首页 > 编程语言 > 详细

php 合并数组的方法 非array_merge

时间:2016-01-10 07:02:55      阅读:174      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!