1$collection = collect([1, 2, 3, 4]);
2
3$filtered = $collection->filter(function ($value, $key) {
4 return $value > 2;
5});
6
7$filtered->all();
8
9// [3, 4]
1$collection = collect([1, 2, 3, 4, 5]);
2
3$groups = $collection->split(3);
4
5$groups->toArray();
6
7// [[1, 2], [3, 4], [5]]
1$collection = collect([1, 2, 3]);
2
3$total = $collection->reduce(function ($carry, $item) {
4 return $carry + $item;
5});
6
7// 6
8
9$total = $collection->reduce(function ($carry, $item) {
10 return $carry + $item;
11}, 4);
12
13// 10 | where 4 is a initial value