当我使用Laravel刀片文件foreach循环时,变量可以在foreach循环之后访问,而变量的范围应该只在循环内
@foreach($user->referral as $ref) <tr> <td>{{ $ref->referral_amount }}</td> <td>{{ $ref->status }}</td> </tr> @endforeach
$ref:这个变量可以在@endforeach之后的endforeach循环之外访问
从
the
foreach
docs开始:
Warning
Reference of a
$value
and the last array element remain even after theforeach
loop. It is recommended to destroy it byunset()
因此,如果要销毁引用,请执行以下操作:
<?PHP unset($ref); ?>
要么:
@PHP unset($ref); @endPHP