简体   繁体   中英

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?

Thanks.

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 .

you can make this into an anon function...

function is_bigger($x,$arry){
    if(max($arry) > $x){
        return false;
    }
}

or as anon function...

$res = function($x,$arry){
    if(max($arry) > $x){
        return false;
    }else{
        return true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM