I have an array that relates a user level to minimum points required for that level, like this:
$userLV = array(0 => 0, 1 => 400, 2 => 800);
The key is the level and the value is the minimum points required for that level.
If a user has a certain number of $points
, I need to find their level by finding the key from the $userLV
array that corresponds to its greatest value less than $points
.
How can I achieve this? (The example array is PHP, but an example in JavaScript or any language will be helpful.)