In this code, the $sum
the variable is initialized to 0 outside the loop. Inside the loop, the subtotal for each item is calculated and added $sum
using the +=
operator. Finally, outside of the foreach
loop, the total sum is printed using {{$sum}}
. This should give you the total sum of all items in the $user_slug_summary
array.
![](https://www.thedataops.org/wp-content/uploads/2023/03/price-1.png)
In html :-
We should writte {{$sum}}. i.e come from foreach.
![](https://www.thedataops.org/wp-content/uploads/2023/03/total1-2.png)
Output :-
![](https://www.thedataops.org/wp-content/uploads/2023/03/total-2.png)