Click here to Skip to main content
14,690,956 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
is this the correct way to sum up loop values?
it is not working....

What I have tried:

@foreach($sum as $ind=>$dtl)
         <?php
             $total = 0;
             $total += $dtl->amount;
         ?>
   @endforeach
         <tr>
             <th>TOTAL</th>
             <td><input type="text" type="number" id="total" name="total"
               value="{{$total}}" /></td>
         </tr>
Posted
Updated 25-Sep-20 0:02am
v2

1 solution

Try that way:
$total = 0;
@foreach($sum as $ind=>$dtl)
         <?php
             $total += $dtl->amount;
         ?>
   @endforeach
         <tr>
             <th>TOTAL</th>
             <td><input type="text" type="number" id="total" name="total"

               value="{{$total}}" /></td>
         </tr>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900