我有一个数组,说
下面的 xyz 是 var_dump($xyz); 的输出
array
7399 =>
array
'count' => int 103
'name' => string '2º SEMESTRE - 2012' (length=23)
7398 =>
array
'count' => int 50
'name' => string '1º SEMESTRE - 2012' (length=23)
7397 =>
array
'count' => int 43
'name' => string '2º SEMESTRE - 2011' (length=23)
7396 =>
array
'count' => int 20
'name' => string '1º SEMESTRE - 2011' (length=23)
7395 =>
array
'count' => int 53
'name' => string '2º SEMESTRE - 2010' (length=23)
'others' =>
array
'name' => string 'Others' (length=6)
'count' => int 65
我想按计数 desc 对这个数组进行排序,名称 asc 将“其他”元素留在底部。我使用了如下的array_multisort
// Obtain a list of columns
foreach ($xyz as $key => $row) {
$count[$key] = $row['volume'];
$name[$key] = $row['edition'];
}
// Sort the data with volume descending, edition ascending
// Add $data as the last parameter, to sort by the common key
array_multisort($count, SORT_DESC, $name, SORT_ASC, $xyz);
但失败了。它显示以下警告:
Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent
我想要的是这样的
array
7399 =>
array
'count' => int 103
'name' => string '2º SEMESTRE - 2012' (length=23)
7395 =>
array
'count' => int 53
'name' => string '2º SEMESTRE - 2010' (length=23)
7398 =>
array
'count' => int 50
'name' => string '1º SEMESTRE - 2012' (length=23)
7397 =>
array
'count' => int 43
'name' => string '2º SEMESTRE - 2011' (length=23)
7396 =>
array
'count' => int 20
'name' => string '1º SEMESTRE - 2011' (length=23)
'others' =>
array
'name' => string 'Others' (length=6)
'count' => int 65
请帮忙。谢谢大家的期待!!!