💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## sortByDesc方法 与 sortBy 方法一样,但是会以相反的顺序来对集合进行排序 与[sortBy](https://www.kancloud.cn/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']] ]; */ ~~~