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: 
You could use [**`array_map()`**](http://php.net/manual/en/function.array-map.php):

```
function add_quotes($str) {
    return sprintf("'%s'", $str);
}

$csv =  implode(',', array_map('add_quotes', $array));

```

[**DEMO**](http://codepad.org/ggNW4RwO)

Also note that there is [**`fputcsv`**](http://php.net/manual/en/function.fputcsv.php) if you want to write to a file.
```
$id = array(2222,3333,4444,5555,6666);
$ids = "'".implode("','",$id)."'";

```

Or
--

```
$ids = sprintf("'%s'", implode("','", $id ) );

```