Possible Duplicate:
How to create comma separated list from array in PHP?
Given this array:
$tags = array('tag1','tag2','tag3','tag4','...');
How do I generate this string (using PHP):
$tags = 'tag1, tag2, tag3, tag4, ...';
Possible Duplicate:
How to create comma separated list from array in PHP?
Given this array:
$tags = array('tag1','tag2','tag3','tag4','...');
How do I generate this string (using PHP):
$tags = 'tag1, tag2, tag3, tag4, ...';
Yes you can do this by using implode
$string = implode(', ', $tags);
And just so you know, there is an alias of implode, called join
$string = join(', ', $tags);
I tend to use join more than implode as it has a better name (a more self-explanatory name :D )
implode
instead of join
, not sure why, but I find that explode-implode is more common in most codebases I've worked on now, and I prefer to align myself with the rest of the codebase in order to maintain a certain level of consistency.