php implode (101) with quotes

Solution 1:

$array = array('lastname', 'email', 'phone');


echo "'" . implode("','", $array) . "'";

Solution 2:

You could use array_map():

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

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

DEMO

Also note that there is fputcsv if you want to write to a file.

Solution 3:

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

Solution 4:

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).