Answers for "The whereIn method removes elements from the collection that do not have a specified item value that is contained within the given array:"

1

The whereIn method removes elements from the collection that do not have a specified item value that is contained within the given array:

$collection = collect([
    ['product' => 'Desk', 'price' => 200],
    ['product' => 'Chair', 'price' => 100],
    ['product' => 'Bookcase', 'price' => 150],
    ['product' => 'Door', 'price' => 100],
]);

$filtered = $collection->whereIn('price', [150, 200]);

$filtered->all();

/*
    [
        ['product' => 'Desk', 'price' => 200],
        ['product' => 'Bookcase', 'price' => 150],
    ]
*/
Posted by: Guest on August-19-2021

Code answers related to "The whereIn method removes elements from the collection that do not have a specified item value that is contained within the given array:"

Browse Popular Code Answers by Language