November 30, 2016 —John Koster
sortByDesc($callback, $options = SORT_REGULAR)
The sortByDesc
method operates exactly the same as the sortBy
method. The only differences is that the sortByDesc
method does not define a $descending
parameter. The sortByDesc
method internally makes a call to the sortBy
method passing true
as the argument for the $descending
parameter.
The following calls to the sortBy
and sortByDesc
methods are functionally equivalent:
{lang="php",line-numbers=on}
1<?php 2 3use Illuminate\Support\Collection; 4 5// Create a new collection instance. 6$collection = new Collection([ 7 ['name' => 'Marshall'] 8]); 9 10$sorted = $collection->sortBy('name', SORT_REGULAR, true);11 12$sorted = $collection->sortByDesc('name', SORT_REGULAR);13 14$sorted = $collection->sortByDesc('name');
∎
The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.