I currently have this:
function isAchievment($number){
while (strlen($number)>1){
$number=$number/10;
}
if ($number!=round($number)){
return(false);
}
$ok=array(1,2,5);
if (in_array($number, $ok)){
return (true);
}
return (false);
}
A player has their overall score (maybe 22000 points). They go to their achievements page and see what they have managed. What it should say is something like:
* You got 1 points!
* You got 2 points!
* You got 5 points!
* You got 10 points!
* You got 20 points!
* You got 50 points!
* You got 100 points!
* You got 200 points!
* You got 500 points!
All the way up to the achievement they should currently get. So in the case of a score of 22000, they should see it up to 20000. The achievements are at 1,2 and 5, them 10,20 and 50 and so on.
At the moment I use a for-loop, from 1 to their score and then if isAchievement($i) i print out "you got $i points!"
It is very slow after about 500...
Has anyone got any idea how to do this a bit faster?
Obviously I could 'hard-code' the function with the actual ok values, and return true if $score = 1 or if score = 500 and so on but what if they have the next multiple of the 1,2,5 sequence say 500,000,000 when I've only coded up to 50,000,000? This seems a bad way to do it...