What is the recommended method in PHP to modify a string like 'test,test1,test2,test3' to have each value surrounded by two single quotes?

When modifying a string like 'test,test1,test2,test3' to have each value surrounded by two single quotes, one recommended method in PHP is to use the explode() function to split the string into an array of values, then loop through the array and add the single quotes around each value. Finally, use implode() to join the modified values back into a single string.

$string = 'test,test1,test2,test3';
$values = explode(',', $string);

foreach ($values as $key => $value) {
    $values[$key] = "'" . $value . "'";
}

$modifiedString = implode(',', $values);

echo $modifiedString;