Re: Basic PHP <> question
I would probably just create parallel arrays. Then, with an if statement, you could figure out what index the # is in between and that would correspond to the level in the other array.
Re: Basic PHP <> question
I would use some math...
$level = (int)(($number*$number_of_levels)/$high_num) + 1
Examples:
If $number is 950, then ...
$level = (int)((950*28)/999999) + 1
$level = 1
If $number is 910,000, then ...
$level = (int)((910000*28)/999999) + 1
$level = 26
Hmmmmmmm.... Not quite... I'm sure it can be refined to work though - maybe a better math whiz than me can figure it out faster.
Re: Basic PHP <> question
Your ranges vary, so I would recommend an array that you would use as a type of lookup:
PHP Code:
$levels = array(1 => 999, 2=> 1999, 3 => 9999 .... );
In order to find the level you would loop through the array and test if the number is higher than the value of that element. If it isn't, the level the current array index.
Re: Basic PHP <> question
PHP Code:
$levelmin = Array();
$levelmin[] = 0;
$levelmin[] = 1000;
$levelmin[] = 2000;
$levelmin[] = 3000;
$levelmin[] = 4000;
//add until all lvls are done, and you can add more later
if($lvl>5) //whatever
{
echo "XP between ".$levelmin[$lvl-1]." and ".$levelmin[$lvl]-1."<br>";
}