I have one array, say xyz
below is output of 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
I want to sort this array by count desc, name asc leaving 'others' element at the bottom. I have used array_multisort like below
// 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);
but failed. It show following warning:
Warning: array_multisort() [function.array-multisort]: Array sizes are inconsistent
Want i want is something like this
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
Please help. Thanking you all in anticipation!!!