[英]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. 还有另一个变量,它拥有一个数字,我需要找出
$num
属于哪个范围。 In the above case $num
falls under 64. (Bigger than 32 and less than 64) 在上述情况下,
$num
小于64。(大于32且小于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 在线演示: http : //ideone.com/KV6MWD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.