Answers for "remove item from collection"

PHP
1

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';
});
Posted by: Guest on February-19-2021

Code answers related to "remove item from collection"

Browse Popular Code Answers by Language