How to filter an array by a condition

后端 未结 7 697
长发绾君心
长发绾君心 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 06:52

    This should work, but I'm not sure how efficient it is as you probably end up copying a lot of data.

    $newArray = array_intersect_key(
                      $fullarray, 
                      array_flip(array_keys($fullarray, 2))
                );
    

提交回复
热议问题