我正在尝试按评级对这个多维数组进行排序。
Array
(
[0] => Array
(
[id] => 4
[image] => test-image.gif
[name] => Mia Panton
[description] => From Falkirk
Wearing: River Island
[month] => 04-2012
[rating] => 0.0000
[votes] => 0
)
[1] => Array
(
[id] => 3
[image] => test-image.gif
[name] => Sam Jane Raggett
[description] => From: Falkirk
Fav Shop: Republic
[month] => 04-2012
[rating] => 1.0000
[votes] => 1
)
[2] => Array
(
[id] => 2
[image] => test-image.gif
[name] => Sasha Westbrooke
[description] => From Falkirk
Wearing: River Island
[month] => 04-2012
[rating] => 4.0000
[votes] => 2
)
[3] => Array
(
[id] => 1
[image] => test-image.gif
[name] => Max Rose-Collins
[description] => From: London
Fav Shop: blah
[month] => 04-2012
[rating] => 3.3333
[votes] => 6
)
)
我正在使用它来这样做
function orderByRating($a, $b) {
return $a['rating'] - $b['rating'];
}
usort($array, 'orderByRating');
但是正如您所看到的,它似乎不起作用,因为 0 在顶部,然后是 1,然后是 4,然后是 3。我不确定这是否与数字是双倍的事实有关?!
任何帮助,将不胜感激。谢谢