企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# sortByDesc方法 与 [sortBy](/collections/sortBy.md) 方法一样,但是会以相反的顺序来对集合进行排序。 ``` $collection = collect([ ['name' => 'Desk', 'colors' => ['Black', 'Mahogany']], ['name' => 'Chair', 'colors' => ['Black']], ['name' => 'Bookcase', 'colors' => ['Red', 'Beige', 'Brown']], ]); $sorted = $collection->sortBy(function ($product, $key) { return count($product['colors']); }); $sorted->values()->all(); /* [ ['name' => 'Bookcase','colors' => ['Red', 'Beige', 'Brown']], ['name' => 'Desk', 'colors' => ['Black', 'Mahogany']], ['name' => 'Chair', 'colors' => ['Black']] ]; */ ```