1

我需要删除所有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)
  }
}
4

2 回答 2

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>';

?>
于 2013-09-21T20:48:32.503 回答
-2

试试这个...

    $farben = array_filter($farben, function($row) { 
if($row["FacetValueCount"] > 3) {
    return $row;
}
});
于 2013-09-21T20:55:44.443 回答