I have a simple two-dimensional array:
$users = array(
array('user' => 'John', 'points' => '0'),
array('user' => 'Paul', 'points' => '0'),
array('user' => 'George', 'points' => '0'),
array('user' => 'Ringo', 'points' => '0')
);
I need to sort them by points (DESC)
and then by name (ASC)
.
This would be my code:
function sortByOrder($a, $b) {
if($b['points'] == $a['points'])
return $a['user'] - $b['user'];
else
return $b['points'] - $a['points'];
}
usort($users, 'sortByOrder');
I get the original order instead of an alphabetical order (since they all have 0 points currently). Why?