码迷,mamicode.com
首页 > Web开发 > 详细

php数据优化

时间:2016-11-14 20:19:31      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:list   car   []   pre   lis   数据   区分   ++   i++   

Array
(
    [0] => Array
        (
            [id] => 19
            [receive_id] => 41
            [mac] => a4:3d:78:fc:49:50
            [staytime] => 400
        )

    [1] => Array
        (
            [id] => 20
            [receive_id] => 42
            [mac] => a4:3d:78:fc:49:51
            [staytime] => 200
        )

    [2] => Array
        (
            [id] => 22
            [receive_id] => 42
            [mac] => a4:3d:78:fc:49:50
            [staytime] => 2443
        )

    [3] => Array
        (
            [id] => 23
            [receive_id] => 42
            [mac] => a4:3d:78:fc:49:50
            [staytime] => 1443
        )

    [4] => Array
        (
            [id] => 24
            [receive_id] => 42
            [mac] => a4:3d:78:fc:49:51
            [staytime] => 1143
        )

    [5] => Array
        (
            [id] => 25
            [receive_id] => 42
            [mac] => a4:3d:78:fc:49:51
            [staytime] => 543
        )

)
举例将以上数组按mac区分成
Array
(
    [a4:3d:78:fc:49:50] => Array
        (
            [id] => 19
            [receive_id] => 41
            [mac] => a4:3d:78:fc:49:50
            [staytime] => 400
            [timmarr] => Array
                (
                    [0] => Array
                        (
                            [id] => 19
                            [receive_id] => 41
                            [mac] => a4:3d:78:fc:49:50
                            [staytime] => 400
                        )

                    [1] => Array
                        (
                            [id] => 22
                            [receive_id] => 42
                            [mac] => a4:3d:78:fc:49:50
                            [staytime] => 2443
                        )

                    [2] => Array
                        (
                            [id] => 23
                            [receive_id] => 42
                            [mac] => a4:3d:78:fc:49:50
                            [staytime] => 1443
                        )

                )

        )

    [a4:3d:78:fc:49:51] => Array
        (
            [id] => 20
            [receive_id] => 42
            [mac] => a4:3d:78:fc:49:51
            [staytime] => 200
            [timmarr] => Array
                (
                    [0] => Array
                        (
                            [id] => 20
                            [receive_id] => 42
                            [mac] => a4:3d:78:fc:49:51
                            [staytime] => 200
                        )

                    [1] => Array
                        (
                            [id] => 24
                            [receive_id] => 42
                            [mac] => a4:3d:78:fc:49:51
                            [staytime] => 1143
                        )

                    [2] => Array
                        (
                            [id] => 25
                            [receive_id] => 42
                            [mac] => a4:3d:78:fc:49:51
                            [staytime] => 543
                        )

                )

        )

)
----------------------
php代码:
$macArr =   [];
$macUserArr = [];
for($i=0;$i<$countList;$i++){
if(!in_array($list[$i][‘mac‘],$macArr)){
$macArr[] = $list[$i][‘mac‘];
$macUserArr[$list[$i][‘mac‘]] = $list[$i];
$macUserArr[$list[$i][‘mac‘]][‘timmarr‘][] = $list[$i];
}else{
$macUserArr[$list[$i][‘mac‘]][‘timmarr‘][] = $list[$i];
}
}
少循环次数

php数据优化

标签:list   car   []   pre   lis   数据   区分   ++   i++   

原文地址:http://www.cnblogs.com/yifan72/p/6062938.html

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