查找数组值之间的值
我有一个大数组,想找到搜索值将出现在哪些数组值之间。
该数组的简化版本如下:
[0] => Array
(
[min] => 0
[max] => 4.999
[val] => low
)
[1] => Array
(
[min] => 5
[max] => 9.999
[val] => med
)
[2] => Array
(
[min] => 10
[max] => 14.999
[val] => high
)
因此,如果我要搜索 6.2,返回的结果将是数组值“med”
是否有一个内置函数可以轻松遍历数组以进行此计算,或者我是否需要设置 foreach 循环
提前致谢
I have a large array and would like to find between which array values the search value would appear.
A simplified version of this array is as follows:
[0] => Array
(
[min] => 0
[max] => 4.999
[val] => low
)
[1] => Array
(
[min] => 5
[max] => 9.999
[val] => med
)
[2] => Array
(
[min] => 10
[max] => 14.999
[val] => high
)
So if I was to search for 6.2 the returned result would be the array value 'med'
Is there a built in function that can easily walk over the array to make this calculation or would I need to set up a foreach loop
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为一个简单的 foreach 就足够快了,只要采取一些预防措施
浮点比较:请参见此处:http://codepad.org/sZkDJJQb
I think a simple foreach would be fast enough, with some precaution in
floating point comparisons : see it here : http://codepad.org/sZkDJJQb