How to add quote to string delimited by comma in PHP

Sometimes we will have a list of string delimited by comma, e.g., a,b,c,d, and we would like to add quote or single quote around each element, e.g., 'a','b','c','d'. It is possible to do so in a line.

$s = "a,b,c,d";
$qs = "'".implode("','",explode(",",$s))."'";

Tags:

Post new comment