1$collection = collect(['Desk', 'Sofa', 'Chair']);
2
3$intersect = $collection->intersect(['Desk', 'Chair', 'Bookcase']);
4
5$intersect->all();
6
7// [0 => 'Desk', 2 => 'Chair']
1use App\Models\User;
2
3$users = $users->intersect(User::whereIn('id', [1, 2, 3])->get());
1$collection = collect([
2 'serial' => 'UX301', 'type' => 'screen', 'year' => 2009
3]);
4
5$intersect = $collection->intersectKey([
6 'reference' => 'UX404', 'type' => 'tab', 'year' => 2011
7]);
8
9$intersect->all();
10
11// ['type' => 'screen', 'year' => 2009]