Best Way To Concatenate Strings In PHP With Spaces In Between

后端 未结 6 2133
抹茶落季
抹茶落季 2021-02-19 22:07

I need to concatenate an indeterminate number of strings, and I would like a space in between two adjoining strings. Like so a b c d e f.

Also I do not want

6条回答
  •  萌比男神i
    2021-02-19 22:46

    I just want to add to deviousdodo's answer that if there is a case that there are empty strings in the array and you don't want these to appear in the concatenated string, such as "a,b,,d,,f" then it will better to use the following:

    $str = implode(',', array_filter(array('a', 'b', '', 'd', '', 'f')));

提交回复
热议问题