If I understand the problem correctly, you would want to first
calculate the totals for each username before outputing your rows.
Make this total part of your $userPoints array ($userPoints[$username]['total']).
Then you should be able to use a PHP sort function that is designed to sort based on the
value in $userPoints[$username]['total'].
After the sort is performed, you can output your rows using the sorted array.
//-- totals
foreach($userPoints as $username => $rounds)
{
$userPoints[$username]['total'] = 0;
for($i = 0; $i < count($rounds); $i++)
$userPoints[$username]['total'] += $rounds[$i];
}
//-- sort
usort($userPoints, "desc"); //if you want ascending order, change 'desc' to 'asc'
//-- now print rows in descending order (or ascending)
// {your code here}
//=======================
// Functions
// ------------------------
// can be placed elsewhere
//=======================
function desc($a, $b)
{
if($a['total'] == $b['total'])
return 0;
else
return ($a['total'] > $b['total']) ? -1 : 1;
}
function asc($a, $b)
{
if($a['total'] == $b['total'])
return 0;
else
return ($a['total'] < $b['total']) ? -1 : 1;
}