如何将用逗号分隔的字符串转换为PHP中的双引号? [重复]

如何将用逗号分隔的字符串转换为PHP中的双引号?  [重复]

问题描述:

This question already has an answer here:

I have a string for example: apple,orange,melon,grape,peach

I want to take the items and display them like this: "apple","orange","melon","grape","peach"

What is the most optimized way to reach this goal?

</div>

此问题已经存在 这里有一个答案: p>

$string = 'apple,orange,melon,grape,peach';
$string = explode(',', $string);
$string = '"' . implode('","', $string) . '"';
echo $string;

Compressed:

$string = 'apple,orange,melon,grape,peach';
echo '"' . implode('","', explode(',', $string)) . '"';