How to convert items in array to a comma separated string in PHP?
PhpArraysPhp Problem Overview
> 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, ...';
Php Solutions
Solution 1 - Php
Use implode:
$tags = implode(', ', array('tag1','tag2','tag3','tag4'));
Solution 2 - Php
Yes you can do this by using [implode][1]
$string = implode(', ', $tags);
And just so you know, there is an alias of implode, called [join][2]
$string = join(', ', $tags);
I tend to use join more than implode as it has a better name (a more self-explanatory name :D )
[1]: http://uk.php.net/manual/en/function.implode.php "implode" [2]: http://uk.php.net/manual/en/function.join.php
Solution 3 - Php
Use PHP function Implode on your array
$mystring = implode(', ',$tags)
Solution 4 - Php
Simply implode:
$tags = implode(", ", $tags);