How to remove integers in array less than X?

前端 未结 2 1077
暖寄归人
暖寄归人 2020-12-11 18:18

I have an array with integers of values from 0 to 100. I wish to remove integers that are less than number X and keep the ones that are equal or greater than number X.

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-11 19:08

    A little ugly using the clunky create_function, but straight forward:

    $filtered = array_filter($array, create_function('$x', 'return $x >= $y;'));
    

    For PHP >= 5.3:

    $filtered = array_filter($array, function ($x) { return $x >= $y; });
    

    Set $y to whatever you want.

提交回复
热议问题