php - 当我在 laravel 的刀片中使用 foreach 时,last() 或 end() 不起作用
问题描述
end()
或last()
不工作...怎么办?
@foreach($students as $student)
@foreach($payment_heads as $payment_head)
<td>
@foreach ($student->payment_detail as $payment_detail_one)
@if($payment_detail_one->payment_head_id==$payment_head->id)
<?php
$total=$total+$payment_detail_one->amount;
?>
@if($payment_detail_one === end($$student->payment_detail))
{{$payment_detail_one->amount}}
@endif
@endif
@endforeach
</td>
@endforeach
@endforeach
解决方案
请参阅文档https://laravel.com/docs/5.5/blade#the-loop-variable。
错end($$student->payment_detail)
用了 double$$
你可以用这个
@foreach($students as $student)
@foreach($payment_heads as $payment_head)
<td>
@foreach ($student->payment_detail as $payment_detail_one)
@if($payment_detail_one->payment_head_id==$payment_head->id)
<?php
$total = $total + $payment_detail_one->amount;
?>
@if ($loop->last)
{{$payment_detail_one->amount}}
@endif
@endif
@endforeach
</td>
@endforeach
@endforeach
推荐阅读
- c# - 面向客户的 ASP.NET CORE 3.1 自定义 Razor 页面路由
- r - Shinyapps.io 门户中的基本闪亮应用程序中的上传错误
- angular - 使用多个 PouchDB 实例在多个 CouchDB 节点之间共享数据
- python - 将文件夹名称添加到导出的文件
- javascript - 在 Bootstrap 中以编程方式关闭模式对话框并在提交时显示另一个页面
- apache - Nginx 作为 Apache 的反向代理
- r - 从源 R 安装包
- csv - 如何将多个唯一命名的 CSV 附件从 GMAIL 导入到 GOOGLESHEETS
- c++ - 我该如何处理这个 C++ Multimap 问题?
- css - CSS fr / 小数单位最小值太大