Best Way To Concatenate Strings In PHP With Spaces In Between

后端 未结 6 2134
抹茶落季
抹茶落季 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条回答
  •  天命终不由人
    2021-02-19 23:09

    considering that you have all these strings collected into an array, a way to do it could be trough a foreach sentence like:

    $res = "";
    foreach($strings as $str) {
       $res.= $str." ";
    }
    
    if(strlen($res > 0))
        $res = substr($res,-1);
    

    in this way you can have control over the process for future changes.

提交回复
热议问题