亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從來自 api 的表列中獲取總金額的總和

從來自 api 的表列中獲取總金額的總和

PHP
哆啦的時光機 2023-07-08 21:42:35
我有一個具有唯一編號的 api,該編號不同,因此當我使用該唯一編號調用 api 時,我會返回數據,并在表中顯示數據。該表有一個列名稱“amount”。由于其動態數據來自 API,我只是困惑如何在表格的最底部顯示總量。我正在使用 Laravel。我的代碼示例<table class="table table-one">       <thead class="table-success">            <tr>                <th scope="col">Inst. No.</th>                <th scope="col">PR No.</th>                <th scope="col">PR Date</th>                 <th scope="col">Prem. Amt.</th>            </tr>        </thead><!-- ends: thead -->        <tbody>         @foreach ($results['polinfo'] as $data)           @foreach ($data['poldata'] as $res)            <tr>                <th scope="row">{{$res['INSTALNO']}}</th>                <td>{{$res['PR_NO']}}</td>                <td>{{$res['PR_DATE']}}</td>                <td>{{$res['AMOUNT']}}</td>            </tr>       @endforeach         @endforeach        </tbody><!-- ends: tbody -->    </table>我必須計算所有 {{$res['AMOUNT']}} 并必須將其顯示為總金額。
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻1812條經驗 獲得超5個贊

如果您只需要后面的值,foreach您可以使用一個單獨的變量來添加金額:


@php($amount = 0)


@foreach ($results['polinfo'] as $data) 

    @foreach ($data['poldata'] as $res)

        <tr>

            <th scope="row">{{$res['INSTALNO']}}</th>

            <td>{{$res['PR_NO']}}</td>

            <td>{{$res['PR_DATE']}}</td>

            <td>{{$res['AMOUNT']}}</td>

        </tr>

        

        @php($amount += (int) $res['AMOUNT'])

    @endforeach

@endforeach


Amount: {{ $amount }}


查看完整回答
反對 回復 2023-07-08
  • 1 回答
  • 0 關注
  • 142 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號