Home » Php » php – Implode with double quotes as separator

php – Implode with double quotes as separator

Posted by: admin July 12, 2020 Leave a comment

Questions:

I have this right now:

$_words = "'".implode("','", $array_of_words)."'";

Which gives me a string like:

'word','word2','word3'

How can I modify that to get

"word","word2","word3"

Thanks

How to&Answers:

Just swap your quotes

$_words = '"'.implode('","', $array_of_words).'"';

Answer:

$result=array();
foreach ($array_of_words as $a1) {
    $result[]='"'.$a1.'"';
}
$_words = implode( ',', $result );
echo $_words;                   

Answer:

$_words = implode( "','", $array_of_words );