How to determine if a given number exists in a given array range?

I have an array that stores numbers. The number of numbers changes from time to time. There is another variable that contains a number, and I need to find out in which range $num falls. In the above case, $num drops to 64. (More than 32 and less than 64)

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

How to do it?

+4
source share
1 answer
 $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

+6
source

Source: https://habr.com/ru/post/1481374/


All Articles