我覺得你的問題一定是你所使用的實際的排序功能,下面是如何在乙醚升序或一個完整的例子降序。
$array = array(
array('event'=> 'something', 'Weight' => 2),
array('event'=> 'something', 'Weight' => 1),
array('event'=> 'something', 'Weight' => 10),
array('event'=> 'something', 'Weight' => 10),
array('event'=> 'something', 'Weight' => 0),
array('event'=> 'something', 'Weight' => 1),
array('event'=> 'something', 'Weight' => -10),
);
function weightCmp($isAscending = true) {
return function($a, $b) use ($isAscending) {
$diff = $a['Weight'] - $b['Weight'];
return $isAscending ? $diff : $diff * -1;
};
}
usort($array, weightCmp());
var_dump($array);
usort($array, weightCmp(false));
var_dump($array);
實際啓動排序的行在哪裏?必須有'usort()'之類的東西。這是一個正確的例子:https://eval.in/79635 – ComFreek