php implode (101) with quotes php implode (101) with quotes arrays arrays

php implode (101) with quotes


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


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.


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