This is how I explode a sentence into an array of words:
这就是我将一个句子分解成一个单词数组的方法:
$words = explode(" ", $sentence)
;
$ words = explode(“”,$ sentence);
How do you do the opposite? (take an array such as $words
with single numeric keys into a variable storing a string such as $sentence
with spaces between words)
你怎么做相反的事情? (将带有单个数字键的$ words等数组放入存储字符串的变量中,如$ sentence,单词之间有空格)
5 个解决方案
#1
20
http://php.net/manual/en/function.implode.php
http://php.net/manual/en/function.implode.php
$sentence = implode(' ',$words);
#3
2
use implode
使用内爆
http://php.net/manual/en/function.implode.php
http://php.net/manual/en/function.implode.php
#5
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
#1
20
http://php.net/manual/en/function.implode.php
http://php.net/manual/en/function.implode.php
$sentence = implode(' ',$words);
#2
#3
2
use implode
使用内爆
http://php.net/manual/en/function.implode.php
http://php.net/manual/en/function.implode.php
#4
#5
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