我想使用implode函数implode(" ",$array);
,但我不想在每个数组元素之间留一个空格。例如,如果数组是$array = array("M.","Benz","wants","to","marry","A.","Marry");
,我不希望在M.Benz
和A.Marry
之间留出空格。
答案 0 :(得分:0)
如果您只想替换M.Benz
和A.Marry
中的空格,请将str_replace与您的代码一起使用。
$array = array("M.","Benz","wants","to","marry","A.","Marry");
$str = implode(" ",$array);
echo $str = str_replace(". ", ".", $str);