Question: Imploding a simple array 

would look like this

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

```

and that would return this

```
 lastname,email,phone

```

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 

```
 'lastname','email','phone'

```

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: 
If you want to avoid the fopen/fputcsv sub-systems here's a snippet that builds an escaped CSV string from an associative array....

```
$output = '';
foreach ($list as $row) {
  $output .= '"' . implode('", "', array_values($row)) . '"' . "\r\n";
}

```

Or from a list of objects...

```
foreach ($list as $obj) {
  $output .= '"' . implode('", "', array_values((array) $obj)) . '"' . "\r\n";
}

```

Then you can output the string as desired.
I think this is what you are trying to do

```
$array = array('lastname', 'email', 'phone');
echo "'" . implode("','", explode(',', $array)) . "'";

```