How to calculate value in Foreach Loop

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.

In html :-

We should writte {{$sum}}. i.e come from foreach.

Output :-