Laravel 8 sortDesc() {#collection-method}
2021-07-02 18:05 更新
该方法与 sort 方法一样,但是会以相反的顺序来对集合进行排序:
$collection = collect([5, 3, 1, 2, 4]);
$sorted = $collection->sortDesc();
$sorted->values()->all();
// [5, 4, 3, 2, 1]
与 sort 不同,你不能传递回调函数给 sortDesc。如果你想要使用回调函数,你可以使用 sort 颠倒比较。
以上内容是否对您有帮助:

免费 AI IDE


更多建议: