How to filter an array by a condition

后端 未结 7 704
长发绾君心
长发绾君心 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:02

    I might do something like:

    $newarray = array();
    foreach ($jsonarray as $testelement){
        if ($testelement == 2){$newarray[]=$testelement}
    }
    $result = count($newarray);
    

提交回复
热议问题