Search code examples
phparrayscomparison

Check if there is a bigger number than X in array


I need a function, without looping, that checks if the array values are bigger than a number of my choice X. If there is, return false.

Is there a nice efficient way to do this? Maybe some anonymous function?


Solution

  • A simple solution would be to use min [docs]:

    if (min($values) > $my_value) {
        // all values are larger
    }
    

    You can find other solutions in this similar question: PHP: Check to see if all the values in an array are less than x.