Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel group collection and sort by the biggest value

//assuming your collection is called $items

$sorted = $items->groupBy('type')
            ->map(function($group){
              return $group->sortByDesc('probability')->take(1);
            })
            ->flatten(1);
 
PREVIOUS NEXT
Tagged: #Laravel #group #collection #sort #biggest
ADD COMMENT
Topic
Name
9+2 =