我需要删除FacetValueCount
低于3
的所有元素。
我该怎么做?
这是我的数组:数组名称为$farben
array(8) {
[0]=>
array(2) {
["FacetValueName"]=>
string(4) "Blau"
["FacetValueCount"]=>
int(5)
}
[1]=>
array(2) {
["FacetValueName"]=>
string(7) "Schwarz"
["FacetValueCount"]=>
int(3)
}
[2]=>
array(2) {
["FacetValueName"]=>
string(4) "blue"
["FacetValueCount"]=>
int(2)
}
[3]=>
array(2) {
["FacetValueName"]=>
string(4) "Grau"
["FacetValueCount"]=>
int(1)
}
}
答案 0 :(得分:2)
<?php
$farben = ARRAY();
$farben[] = array('FacetValueName'=>'Blau', 'FacetValueCount' => 5);
$farben[] = array('FacetValueName'=>'Schwarz', 'FacetValueCount' => 3);
$farben[] = array('FacetValueName'=>'blue', 'FacetValueCount' => 2);
$farben[] = array('FacetValueName'=>'Grau', 'FacetValueCount' => 1);
print '<pre>'; var_dump($farben); print '</pre>';
foreach ($farben AS $key => $row) {
if ($row['FacetValueCount'] < 3) { unset($farben[$key]); }
}
print '<pre>'; var_dump($farben); print '</pre>';
?>
答案 1 :(得分:-2)
试试这个......
$farben = array_filter($farben, function($row) {
if($row["FacetValueCount"] > 3) {
return $row;
}
});