$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就是返回的结果数组