我正在尝试使用foreach循环执行if else语句但由于某种原因我收到此错误
解析错误:语法错误,意外'elseif'(T_ELSEIF)。
我知道这是一个简单的错误,但我似乎无法确定这里有什么问题,我是否错误地执行了我的代码?还是需要关闭的东西? (对于结束部分,我已经检查过,我真的没有看到任何问题)有人可以帮助我吗?非常感谢
profile.blade.php
@foreach($data as $value)
<tr>
@if($value->training_Status == 'No')
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
@foreach($data1 as $value1)
@elseif(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
@endforeach
@else
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
@endif
</tr>
@endforeach
答案 0 :(得分:1)
您可以更改为
@foreach($data as $value)
<tr>
@if($value->training_Status == 'No')
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
@foreach($data1 as $value1)
@if(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
@endif
@endforeach
@else
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
@endif
</tr>
@endforeach
答案 1 :(得分:1)
@foreach($data as $value)
<tr>
@if($value->training_Status == 'No')
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
@foreach($data1 as $value1)
@if(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
@endif
@endforeach
@else
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
@endif
</tr>
@endforeach
应该为你做的工作
答案 2 :(得分:1)
@Dkna只需将您的代码更改为:
@foreach($data as $value)
<tr>
@if($value->training_Status == 'No')
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: blue;">{{$value->Name}}</span></a></th>
@foreach($data1 as $value1)
@if(($value1->blacklist == 'Yes') && ($value1->name == $value->Name))
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}"><span style="color: red;">{{$value->Name}}</span></a></th>
@endif
@endforeach
@else
<th><a href="{{route('user.show',['id'=>$value->pi_id])}}">{{$value->Name}}</a></th>
@endif
</tr>
@endforeach
希望这可以帮助您并解决您的问题!