I have a array with the lvl=>xp correspondance and I would make a function that return the lvl for a specific xp. like $lvl = getLvlOf(15084); //return 5
$lvl_correspondance = array(
1=>100,
2=>520,
3=>2650,
4=>6588,
5=>12061,
6=>23542,
...
n=>xxxxxx
);
I search the easyest and ressourceless way to do it.
Sorry for my poor english 🙁
Assuming the level values in the array are kept sorted, e.g. (it’s 100,200,300, 400, etc… and not 200,500,100,300,400), then a simple scan will do the trick:
That’ll iterate through the array, and jump out as soon as the XP level in the array is larger than the XP level you’re looking for, leaving the key of that “last” level in $last_key