php - finding keys in an array that match a pattern

前端 未结 6 600
刺人心
刺人心 2020-12-10 11:13

I have an array that looks like:

 Array ( [2.5] => ABDE [4.8] => Some other value ) 

How would I find any key/value pair where the k

6条回答
  •  佛祖请我去吃肉
    2020-12-10 11:54

    To get just the part of the array with matching keys you could also write

    $matching_array = array_flip(preg_grep($pattern, array_flip($your_array)));
    

    This might just lead to problems performance-wise, if your array gets too big.

提交回复
热议问题