|
Posted by bobmct on 09/29/05 06:49
Gentlemen;
Can someone recommend the best way to search a single dimension array?
I'm currently using a for loop and it doesn't seem to be working
accurately. Here's an example:
$_AV=array(0 => '0100',
1 => '0200',
2 => '0300',
3 => '0400',
4 => '0500'
};
$arg="0225";
for($X=count($_AV);$X>=0;$X--) {
if ($_AV[$X] > $arg) {
$result=$X;
break;
}
}
According to my requirements, the result should be set to 1 which is
the index to the element that is either equal to or less than but
closest to the $arg value.
Is there a better way to accomplish this??
Any/all suggestions appreciated.
Thanks
Navigation:
[Reply to this message]
|