remove item from collection

141

remove item from collection -

$collection = collect(['name' => 'taylor', 'framework' => 'laravel']);

// The forget method removes an item from the collection by its key:
$collection->forget('name');
// The pull method removes and returns an item from the collection by its key:
$collection->pull('name');
// The reject method filters the collection using the given closure.
// The closure should return true if the item should be removed from the resulting collection:
$filtered = $collection->reject(function ($value) {
    return $value == 'taylor';
});

Comments

Submit
0 Comments