« Fly Naked | Main | Habitat Espresso Televised Media Coverage from 1997-2001 »

PHP tip: Comma Separated Values (CSV) List to Array and Array to CSV List

from PHP Snippets DB:

// create a comma separated list from an array
$array = array('green','purple','blue','yellow','amber','red');
$comma_separated = implode(",", $array);
echo $comma_separated;

// create an array from a comma separated list
$list = "green, purple, blue, yellow, amber, red";
$array = explode(',', $list);
print_r($array);

Technorati Tags: ,

Comments

Rizwan Pervaiz

Good.
Thanx.

Darren Fauth

Nice. Thanks for having this available. I knew I could do it with php...and you saved me the time of RTFM...haha. Thanks.

Post a comment

Comments are moderated, and will not appear on this weblog until the author has approved them.

If you have a TypeKey or TypePad account, please Sign In.