i have users, and they each have a number, the higher the number the better, i want to give the users ranks, 1 being the highest.
I tried
[CODE]
$array = array(‘8′, ’65’, ‘2’, ’45’);
rsort($array);
while (list($key, $val) = each($array)) {
$key2 = $key + 1;
echo ‘Rank ‘ . $key2 . ‘: ‘ . $val . “APn”;
}
that puts the numbers in the right order and gives a rank, but i have no way of matching these results to the username. How can this be achieved?
Can i do something like this:
[CODE]
$array = array(‘usera’ => ’65’, ‘userb’ => ‘6’, ‘userc’ => ’23’, ‘userd’ => ‘4’);
rsort($array);
while (list($key, $val) = each($array)) {
$key2 = $key + 1;
echo ‘Rank ‘ . $key2 . ‘: ‘ . $val . “APn”;
}
but then i would need to get the key value into the loop, but it’s already in the loop as a number. Is there a better way, or a way that works?
Thanks