PHP Sorting array of arrays by 3 fields (gold,silver,bronze)

Posted by
$arr = array(
Array(
'country_id' => 3,
'country_name' => 'Russia',
'gold' => 23,
'silver' => 21,
'bronze' => 28,
'total' => 72,
),
Array(
'country_id' => 189,
'country_name' => 'USA',
'gold' => 36,
'silver' => 38,
'bronze' => 36,
'total' => 10,
),
Array(
'country_id' => 230,
'country_name' => 'Germany',
'gold' => 16,
'silver' => 10,
'bronze' => 15,
'total' => 41,
),
Array(
'country_id' => 231,
'country_name' => 'China',
'gold' => 51,
'silver' => 21,
'bronze' => 28,
'total' => 100,
)
);

function mySort($a,$b) {
if ($b['gold'] == $a['gold']) {
if ($b['silver'] == $a['silver']) {
if ($b['bronze'] == $a['bronze']) {
return strcmp($b['country_name'], $a['country_name']);
} else {
return $b['bronze'] - $a['bronze'];
}
} else {
return $b['silver'] - $a['silver'];
}
} else {
return $b['gold'] - $a['gold'];
}
}

uasort($arr, 'mySort');
print_r($arr);