I have an associative array from a loop where I store a user_id (key) and a score (value)
$scores[$user_id] = $score;
I was wondering, after this loop has finished, how can I sort the values (get the ten highest scores) and get their keys.
I have an associative array from a loop where I store a user_id (key) and a score (value)
$scores[$user_id] = $score;
I was wondering, after this loop has finished, how can I sort the values (get the ten highest scores) and get their keys.
asort($scores);
$tenHighest = array_slice($scores, -10, null, true);
$tenHighestKeys = array_keys($tenHighest);