When looping, the vertical bar "|" separator between each item is not required at the beginning and end. What needs to be done?
The effect to be achieved: (no vertical lines at the beginning and end)
<code><a href="#">桃子</a> | <a href="" >苹果</a></span> | <a href="" >香蕉</a></span></code>
Loop like the following, either with a vertical line at the beginning or at the end:
<code>@foreach ($goods->fruits as $ fruit) <a href="#">{{$fruit->name}}</a> | @endforeach</code>
Question:
What should I do so that there are no vertical lines at the beginning and end?
When looping, the vertical bar "|" separator between each item is not required at the beginning and end. What needs to be done?
The effect to be achieved: (no vertical lines at the beginning and end)
<code><a href="#">桃子</a> | <a href="" >苹果</a></span> | <a href="" >香蕉</a></span></code>
Loop like the following, either with a vertical line at the beginning or at the end:
<code>@foreach ($goods->fruits as $ fruit) <a href="#">{{$fruit->name}}</a> | @endforeach</code>
Question:
What should I do so that there are no vertical lines at the beginning and end?
<code>@foreach ($goods->fruits as $key => $fruit) <a href="#">{{ $fruit->name }}</a> @if ($key + 1 !== count($goods->fruits)) | @endif @endforeach</code>
Specially handle the first or last item.
Use join() directly. This function can be realized perfectly.