|
Posted by David T. Ashley on 07/03/07 21:25
I have an array of a few hundred integers, ordered in ascending order.
Given an integer input, I'd like to find the index in the array of the
element $array[$i] such that it is equal to or less than the input but
$array[$i+1] is larger.
I couldn't find a function to deal with arrays that does anything except
look for an exact match.
Are there any built-in functions that will search in a "bracketed" way
rather than look for an exact match?
For example,
$a = array( 10, 50, 250, 1000, 20000, 40000 );
If the input is 20,039 (for example), I'd want the output of the function to
be 4, because $a[4] is the element just below 20,001.
Any such built-in function?
--
David T. Ashley (dta@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Navigation:
[Reply to this message]
|