首页 > 代码库 > php数据优化
php数据优化
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数据优化
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。