在laravel/blade中从数组创建逗号分隔列表? [英] Create comma separated list from array in laravel/blade?
本文介绍了在laravel/blade中从数组创建逗号分隔列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在显示数组@foreach($tags as $tag)$tag->@endforeach
的元素.输出为tag1tag2tag3
.在tag1,tag2,tag3
中sho数组元素的可能方法是什么.以及如果数组中只有一个元素,如何不显示,
.
I am displaying elements of an array @foreach($tags as $tag)$tag->@endforeach
. The output is tag1tag2tag3
. What is the possible way to sho elements of array in tag1,tag2,tag3
. And how to not show,
if there is only one element in array.
推荐答案
implode()
非常适合回显简单数据.在实际项目中,您通常希望向循环中添加一些HTML或逻辑,请使用
implode()
is good for echoing simple data. In real project you usually want to add some HTML or logic into the loop, use $loop
variable which is available since 5.3:
@foreach ($arrayOrCollection as $value)
{{ $loop->first ? '' : ', ' }}
<span class="nice">{{ $value->first_name }}</span>
@endforeach
这篇关于在laravel/blade中从数组创建逗号分隔列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文