speed up execution of this php operation?

Spor

New member
I created this function to loop through an array and find the value that fits between a range of numbers:

global $levels;
$xp = (int)$xp;
asort($levels);
reset($levels);
while (key($levels)!==false) {
$level = key($levels);
$current = current($levels);
$next = next($levels);
if ($xp >= $current && $xp < $next) {
$level = (int)$level;
return $level;
}
}

the problem is this while() loop takes too long to loop through. short of making my array smaller (all the data is really necessary), is there anything else I could do? does php allow for a quicker method of acting on the array?
 
Back
Top