laravel collection diff

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

showing results for - "laravel collection diff"
Luca
11 Jan 2017
1$collection = collect([1, 2, 3, 4, 5]);
2
3$diff = $collection->diff([2, 4, 6, 8]);
4
5$diff->all();
6
7// [1, 3, 5]
Daria
12 Mar 2016
1use App\Models\User;
2
3$users = $users->diff(User::whereIn('id', [1, 2, 3])->get());
Emilia
18 Jan 2021
1$collection = collect([
2    'one' => 10,
3    'two' => 20,
4    'three' => 30,
5    'four' => 40,
6    'five' => 50,
7]);
8
9$diff = $collection->diffKeys([
10    'two' => 2,
11    'four' => 4,
12    'six' => 6,
13    'eight' => 8,
14]);
15
16$diff->all();
17
18// ['one' => 10, 'three' => 30, 'five' => 50]