我下面有两个多维数组。
$filter=array(1,3);
和
$data= array(
array( "name"=>'milind', "flt"=>array(1,2,3,4) ),
array( "name"=>'bhuvad', "flt"=>array(3,4) )
);
我尝试了下面的代码过滤器
$count = count($data);
$new = array();
for($x=0;$count>$x;$x++){
foreach($data[$x]["flt"] as $flt){
if(in_array($flt,$filter)){
$new[]=$data[$x];
}
}
}
print_r($new);
得到的结果类似
array(
[0] => Array ( [name] => milind [flt] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) ),
[1] => Array ( [name] => milind [flt] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) ),
[2] => Array ( [name] => bhuvad [flt] => Array ( [0] => 3 [1] => 4 ) )
)
我想要的结果是
array(
[0] => Array ( [name] => milind [flt] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) ),
[1] => Array ( [name] => bhuvad [flt] => Array ( [0] => 3 [1] => 4 ) )
)
如果我使用array_unique()来移动重复的数组,得到下面的结果。
array(
[0] => Array ( [name] => milind [flt] => Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 ) )
)
1条答案
按热度按时间2ul0zpep1#
我希望这能帮助你。