Laravel - Collections - Method Partition

The partition method may be combined with PHP array destructuring to separate elements that pass a given truth test from those that do not:

    
    $collection = collect([1, 2, 3, 4, 5, 6]);
    
    [$underThree, $equalOrAboveThree] = $collection->partition(function ($i) {
        return $i < 3;
    });
    
    $underThree->all();
    
    // [1, 2]
    
    $equalOrAboveThree->all();
    
    // [3, 4, 5, 6]