mcgrailm mcgrailm - 1 year ago 123
PHP Question

php implode (101) with quotes

Imploding a simple array

would look like this

$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);

and that would return this


great, so i might do this instead

$array = array('lastname', 'email', 'phone');
$comma_separated = implode("','", $array);
$comma_separated = "'".$comma_separated."'";

and now i have what I want a nice pretty csv string


is there a better way to do this, it feels to me like there should be an optional parameter for implode am I missing something ?

Answer Source

No, the way that you're doing it is just fine. implode() only takes 1-2 parameters (if you just supply an array, it joins the pieces by an empty string).