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
1$collection = collect([1, 2, 3]);
2
3$total = $collection->reduce(function ($carry, $item) {
4 return $carry + $item;
5});
6
7// 6