Possible Duplicate:
How to create comma separated list from array in PHP?可能重复:如何在PHP中从数组中创建逗号分隔的列表?
Given this array:
鉴于这个数组:
$tags = array('tag1','tag2','tag3','tag4','...');
How do I generate this string (using PHP):
如何生成这个字符串(使用PHP):
$tags = 'tag1, tag2, tag3, tag4, ...';
4 个解决方案
#2
15
Yes you can do this by using implode
是的,你可以通过内爆实现
$string = implode(', ', $tags);
And just so you know, there is an alias of implode, called join
大家知道,内爆的别名是join
$string = join(', ', $tags);
I tend to use join more than implode as it has a better name (a more self-explanatory name :D )
我倾向于使用连接,而不是内爆,因为它有一个更好的名称(一个更自我解释的名称:D)
#4
6
Simply implode:
简单的崩溃:
$tags = implode(", ", $tags);
#1
#2
15
Yes you can do this by using implode
是的,你可以通过内爆实现
$string = implode(', ', $tags);
And just so you know, there is an alias of implode, called join
大家知道,内爆的别名是join
$string = join(', ', $tags);
I tend to use join more than implode as it has a better name (a more self-explanatory name :D )
我倾向于使用连接,而不是内爆,因为它有一个更好的名称(一个更自我解释的名称:D)
#3
#4
6
Simply implode:
简单的崩溃:
$tags = implode(", ", $tags);