为什么在if语句中定义的for循环语句中变量$ myVar未定义,如下所示(Laravel 5.2中的刀片模板)?
$myVar = [];
@if (empty($myVar))
Var is empty.
@endif
@foreach ($myVar as $var)
<li>{{$var}}</li>
@endforeach
答案 0 :(得分:0)
也尝试isset
$myVar = [];
@if (empty($myVar))
Var is empty.
@endif
@if (isset($myVar))
Var is isset.
@endif
@foreach ($myVar as $var)
<li>{{$var}}</li>
@endforeach
答案 1 :(得分:0)
我通过更改返回视图('process',withMyVar($ myVar); with view('process',compact($ myVar);
)使其工作