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: 
**Don't forget to escape your data!**
If you want to put data in a CSV file without [fputcsv](https://www.php.net/manual/en/function.fputcsv.php) function or put it in a SQL query use this code:

```
$comma_separated = "'" . implode("','", array_map('addslashes', $array)) . "'";

```

This code avoids SQL injection or data fragmentation when input array contains **single quotation** or **backslash** characters.
you can do it this way also

```
<?php
$csv= '\'' . join(array('lastname', 'email', 'phone'),'\',').'\'';
echo $csv;
?>

```