内含函数,但不是每个数组元素

时间:2016-12-11 11:54:41

标签: php arrays string-matching

我想使用implode函数implode(" ",$array);,但我不想在每个数组元素之间留一个空格。例如,如果数组是$array = array("M.","Benz","wants","to","marry","A.","Marry");,我不希望在M.BenzA.Marry之间留出空格。

1 个答案:

答案 0 :(得分:0)

如果您只想替换M.BenzA.Marry中的空格,请将str_replace与您的代码一起使用。

$array = array("M.","Benz","wants","to","marry","A.","Marry");
$str = implode(" ",$array);
echo $str = str_replace(". ", ".", $str);