The vertical line between each item in the Loop "|" separator, the tail and the need not, how to do it?
The effect to be achieved: (No vertical line at the tail)
桃子 | 苹果 | 香蕉
Loop like this, either the head or the tail has a vertical line:
@foreach ($goods->fruits as $ fruit) {{$fruit->name}} |@endforeach
Problem:
What do you have to do to have no vertical line?
Reply content:
The vertical line between each item in the Loop "|" separator, the tail and the need not, how to do it?
The effect to be achieved: (No vertical line at the tail)
桃子 | 苹果 | 香蕉
Loop like this, either the head or the tail has a vertical line:
@foreach ($goods->fruits as $ fruit) {{$fruit->name}} |@endforeach
Problem:
What do you have to do to have no vertical line?
@foreach ($goods->fruits as $key => $fruit) {{ $fruit->name }} @if ($key + 1 !== count($goods->fruits)) | @endif@endforeach
Special handling of the first or last item.
Use join directly (). This function can be implemented perfectly.