简体   繁体   中英

How to identify if given number is there in a given array range?

I have an array which stores numbers. The count of numbers varies time to time. There is another variable which a holds number, and I need to find out in which range $num falls. In the above case $num falls under 64. (Bigger than 32 and less than 64)

$ar = array(0, 32, 64, 96, 128, 160, 192, 224);

$num = 44;

How do I crack this?

$ar = array(0, 32, 64, 96, 128, 160, 192, 224);

$num = 44;

$range = min(array_filter($ar, function($i) use($num) {
    return $i > $num;
}));

var_dump($range);

Online demo: http://ideone.com/KV6MWD

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