How to convert items in array to a comma separated string in PHP? [duplicate]

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, ...';

Use implode:

 $tags = implode(', ', array('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 )


Use PHP function Implode on your array

$mystring = implode(', ',$tags)