每次 foreach 回傳時,它都會用 values[0] 寫入元素,因為 $i=0。我希望 foreach 在第一次回傳時列印 values[0],在第二次回傳時列印 values[1]。我應該在哪里做for回圈?
@foreach ($videohistories as $videohistory)
<tr>
<td>{{ date("Y-m-d H:i:s", $videohistory->create_time) }}</td>
<td>{{ date("Y-m-d H:i:s", $videohistory->end_time) }}</td>
<td>{{ diff_date_format($videohistory->begin_time, $videohistory->end_time, "%H sa %i dk. %s sn") }}</td>
<td>
@for($i = 0; $i < $values; $i ) {{$values[$i]}} @break @endfor </td>
</tr>
@endforeach
uj5u.com熱心網友回復:
您在每次迭代中執行一個 for 回圈,然后在該循??環的第一次迭代中中斷。如果要根據foreach
迭代列印第 i 個元素,則需要使用$loop
變數
@foreach ($videohistories as $videohistory)
<tr>
<td>{{ date("Y-m-d H:i:s", $videohistory->create_time) }}</td>
<td>{{ date("Y-m-d H:i:s", $videohistory->end_time) }}</td>
<td>{{ diff_date_format($videohistory->begin_time, $videohistory->end_time, "%H sa %i dk. %s sn") }}</td>
<td>
@if (isset($values[$loop->index]))
{{$values[$loop->index]}}
@endif
</td>
</tr>
@endforeach
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491085.html
標籤:php 拉拉维尔 for循环 前锋 laravel-刀片