Implode with double quotes as separator
Asked Answered
S

3

10

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

Stenograph answered 21/1, 2013 at 14:27 Comment(0)
I
31

Just swap your quotes

$_words = '"'.implode('","', $array_of_words).'"';
Intisar answered 21/1, 2013 at 14:28 Comment(3)
You forgot to swap starting and ending quotes :)Doridoria
They are actually because what you wrote echoes 'word","word2","word3'Doridoria
I changed it. It wasn't important to show them the solution to their problem but it makes sense to give a complete answer.Intisar
M
0
$result=array();
foreach ($array_of_words as $a1) {
    $result[]='"'.$a1.'"';
}
$_words = implode( ',', $result );
echo $_words;                   
Mcgrath answered 14/10, 2013 at 10:35 Comment(0)
B
0

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

Bingle answered 2/1, 2016 at 23:44 Comment(1)
Please add some explanation to your answer. Code-only answers are generally considered to be of low quality.Sam

© 2022 - 2024 — McMap. All rights reserved.