php过滤数组

$str='PC,ANDROID';
$res=[['from_platform'=>'PC','user_num'=>200],['from_platform'=>'ANDROID','user_num'=>100],['from_platform'=>'IOS','user_num'=>400]];
要实现的结果:

Array
(
[0] => Array
(
[from_platform] => PC
[user_num] => 200
)

[1] => Array
(
[from_platform] => ANDROID
[user_num] => 100
)

)

 

代码:

$filter_arr=array_filter($res,function($item) use($str) {
if($str){
$str=str_replace(',',',',$str);
$str_arr=explode(',',$str);
return in_array($item['from_platform'],$str_arr);
}else{
return true;
}
});


$filter_arr就是返回的结果数组

posted on 2018-05-08 15:42  阳雪凌空  阅读(489)  评论(0编辑  收藏  举报

导航