按数组中的值过滤多维数组 [英] Filter multidimensional array by value in array
本文介绍了按数组中的值过滤多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的数组:
$myArray = array(
array("name"=>"Andrea", "Age"=>17),
array("name"=>"Tresna", "Age"=>20),
array("name"=>"Aria", "Age"=>12)
);
我想按数组中的值过滤该多数组.这是我的过滤器:
I want to filter that multi array by value in array. This is my filter:
$filter = array("Andrea", "Aria");
所以结果必须是这样的:
So the result must be like this:
$newArray = array(
array("name"=>"Andrea", "Age"=>17),
array("name"=>"Aria", "Age"=>12)
);
该怎么做?
推荐答案
提示已经存在,要过滤 ,请使用array_filter
.
The hint is already there, to filter, use array_filter
.
请不要忘记使用use
关键字来导入您的条件.
Don't forget to use use
keyword to import your criteria.
示例:
$newArray = array_filter($myArray, function($e) use ($filter){
// ^ import criteria
return in_array($e['name'], $filter);
});
这篇关于按数组中的值过滤多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文