How to filter an array by a condition

后端 未结 7 670
长发绾君心
长发绾君心 2020-11-22 06:12

I have an array like this:

array(\"a\" => 2, \"b\" => 4, \"c\" => 2, \"d\" => 5, \"e\" => 6, \"f\" => 2)

Now I want to fi

7条回答
  •  隐瞒了意图╮
    2020-11-22 07:09

      foreach ($aray as $key => $value) {
        if (2 != $value) {
          unset($array($key));
        }
      }
    
      echo 'Items in array:' . count($array);
    

提交回复
热议问题