'find sum of $BatterRuns variable in laravel-8

I want to find the sum of the $BatterRuns variable how to do this? Note;_ I am just beginner of laravel This is my index.blade.php

@foreach ($data as $key => $row)
  <tr>
@php
        $BatterRuns = $row->scoreupdateone->one + $row->scoreupdatetwo->two * 2 +
        $row->scoreupdatethree->three * 3 + $row->scoreupdatefour->four * 4 +
        $row->scoreupdatesix->six * 6;
@endphp
         <td>{{ $key + 1 }}</td>
         <td>{{ $row->matchh->match_name }}</td>
         <td>{{ $row->team->team_name }}</td>
         <td>{{ $row->player->player_name }}</td>
         <td>{{ $BatterRuns }}</td>
         <td>{{ $row->scoreupdate->out_type }}</td>
         <td>{{ $row->scoreupdateoutbytype->out_by_type }}</td>
         <td>{{ $row->scoreupdateone->one }}</td>
         <td>{{ $row->scoreupdatetwo->two }}</td>
         <td>{{ $row->scoreupdatethree->three }}</td>
         <td>{{ $row->scoreupdatefour->four }}</td>
         <td>{{ $row->scoreupdatesix->six }}</td>
         <td>{{ $row->scoreupdateballsplayed->balls_played }}</td>
@php
         $Balls = $row->scoreupdateballsplayed->balls_played;
@endphp
                                                
@endforeach

Image

This Is what I get you can see the Runs column which i get form $BatterRuns variable.

You can see there is different values in Runs column like 4,6,0 I want sam values of 4+6+0 = 10. I want something like $sum = SUM($BatterRuns); How to do this



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source