Laravel - Collections - Method Skipuntil
The skipUntil
method skips over items from the collection until the given callback returns true
and then returns the remaining items in the collection as a new collection instance:
$collection = collect([1, 2, 3, 4]);
$subset = $collection->skipUntil(function ($item) {
return $item >= 3;
});
$subset->all();
// [3, 4]
You may also pass a simple value to the skipUntil
method to skip all items until the given value is found:
$collection = collect([1, 2, 3, 4]);
$subset = $collection->skipUntil(3);
$subset->all();
// [3, 4]
If the given value is not found or the callback never returnstrue
, theskipUntil
method will return an empty collection.