PHP对多维进行排序,排序依据超过1列


PHP sort multidimensional with more than 1 colum to sort by

可能重复:
如何在php中对多维数组进行排序
用PHP对多维数组进行排序?

如何按高、中、低对数组进行排序(见下文)?

# Generate random events
$severity = array('high','medium','low');
$events = array();
for ($i=1,$n=10;$i<=$n;$i++) {
        $events["Country{$i}"] = array(
                'high'          =>              rand(0,100),
                'medium'        =>              rand(0,100),
                'low'           =>              rand(0,100),
                'total'         =>              'X'
        );
}

我的意思是,在最后一行中,我将有一个排序数组,它包含所有按最高值high、medium和low排序的countryX,所有这些都在一个大数组中。

尝试了不同的方法,但没能得到正确的结果。

function sillySort($a, $b) {
    if ($a['high'] > $b['high']) {
         return -1;
    } else if ($a['high'] < $b['high']) {
         return 1;
    } else {
        if ($a['medium'] > $b['medium']) {
            return -1;
        } else if ($a['medium'] < $b['medium']) {
            return 1;
        } else {
            if ($a['low'] > $b['low']) {
                return -1;
            } else if ($a['low'] < $b['low']) {
                return 1;
            } else {
                return 0;
            }
        }
    }
}
uksort($events, 'sillySort');