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 ?
$comma_separated = "''";
– VitalismIN
expression should be done via a prepared statement -- and here is that canonical: How can I bind an array of strings with a mysqli prepared statement?. This question's minimal reproducible example does not include the challenge of dealing with strings which already contain single quotes -- certainly something to be concerned with to avoid bugs. – Intermixture