laravel collection intersect

Solutions on MaxInterview for laravel collection intersect by the best coders in the world

showing results for - "laravel collection intersect"
Amelie
18 Nov 2019
1$collection = collect(['Desk', 'Sofa', 'Chair']);
2
3$intersect = $collection->intersect(['Desk', 'Chair', 'Bookcase']);
4
5$intersect->all();
6
7// [0 => 'Desk', 2 => 'Chair']
Maya
09 May 2018
1use App\Models\User;
2
3$users = $users->intersect(User::whereIn('id', [1, 2, 3])->get());
Violeta
02 Jan 2017
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]