我有一个像这样的数组
数组 ( [0] => 数组 ( [结果] => 数组 ( [0] => 数组 ( [类型] => ABC [id] => 123232 [名称] => 苹果 ) [1] => 数组 ( [类型] => 防御 [id] => 2323232 [名称] => 香蕉 ) ) [标题] => 酷 [排名] => 2 ) [1] => 数组 ( [结果] => 数组 ( [0] => 数组 ( [类型] => ZX [id] => 3223 [姓名] => 丹尼 ) [1] => 数组 ( [类型] => QWER [id] => 2323232 [名称] => 仙人掌 ) ) [标题] => 热门 [排名] => 1 ) [3].. [4]..还有儿子
我想按排名排序,PHP中有没有快速排序方法可以做到这一点?
usort()
。
下面的示例需要 >= PHP 5.3。如果您没有此版本,只需传递对回调的引用即可。
usort($array, function($a, $b) {
return $a['rank'] - $b['rank'];
}
对数组进行排序有多种方法,请参阅:http://php.net/manual/en/array.sorting.php