首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在laravel-8中求$BatterRuns变量和

在laravel-8中求$BatterRuns变量和
EN

Stack Overflow用户
提问于 2022-05-19 09:17:46
回答 1查看 25关注 0票数 1

我想找到$BatterRuns变量的和,怎么做呢?Note;_,我刚开始吃拉拉,这是我的index.blade.php

代码语言:javascript
复制
@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

这就是我得到的内容,您可以看到Run列,这是我从$BatterRuns变量中得到的。

您可以看到Run列中有不同的值,如4,6,0,我希望sam值为4+6+0 = 10。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-05-19 09:56:30

你可以在你的代码上做类似的事情。

代码语言:javascript
复制
@php
 $totalRun = 0;
@endphp
@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;
        $totalRun = $totalRun + $BattersRuns;

@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
</tr>
<tr>
 <td>{{ $totalRuns }}</td>
</tr>

在for-循环之前声明一个php变量,并在for-循环中使用相同的变量来总结运行。并使用变量$totalRuns显示$battersRun的和。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72301854

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档