当我使用Laravel刀片文件foreach循环时,可以在foreach循环之后访问变量,而变量的作用域应该只在循环内
@foreach($user->referral as $ref)
<tr>
<td>{{ $ref->referral_amount }}</td>
<td>{{ $ref->status }}</td>
</tr>
@endforeach
$ref:此变量可在@endforeach之后从endforeach循环外部访问
发布于 2018-02-26 19:41:29
来自the foreach
docs
警告
即使在foreach
循环之后,$value
和最后一个数组元素的引用也保持不变。建议使用unset()
销毁
因此,如果您想销毁引用,请执行以下操作:
<?php unset($ref); ?>
或者:
@php unset($ref); @endphp
发布于 2018-12-18 15:17:20
建议通过unset()销毁
@php unset($ref); @endphp
https://stackoverflow.com/questions/48987159
复制相似问题