这就是我将一个句子分解为一系列单词的方式:
$words = explode(" ", $sentence)
;
你怎么做相反的事情? (将带有单个数字键的$words
数组放入存储字符串的变量中,例如$sentence
,单词之间有空格)
答案 0 :(得分:24)
http://php.net/manual/en/function.implode.php
$sentence = implode(' ',$words);
答案 1 :(得分:4)
implode()
完全符合您的要求。
答案 2 :(得分:2)
答案 3 :(得分:1)
$sentence = implode(' ', $words);
答案 4 :(得分:1)
$string = "Hello World";
$explode = explode(" ",$string);
print_r($explode); //explode[0] = Hello, explode[1] = World
$explode = array([0]=>Hello,[1]=>World);
$string = implode(" ",$string);
echo $string; // Hello World