remove item from collection

Solutions on MaxInterview for remove item from collection by the best coders in the world

showing results for - "remove item from collection"
Emely
19 Jul 2017
1$collection = collect(['name' => 'taylor', 'framework' => 'laravel']);
2
3// The forget method removes an item from the collection by its key:
4$collection->forget('name');
5// The pull method removes and returns an item from the collection by its key:
6$collection->pull('name');
7// The reject method filters the collection using the given closure.
8// The closure should return true if the item should be removed from the resulting collection:
9$filtered = $collection->reject(function ($value) {
10    return $value == 'taylor';
11});