String concatenation vs array implode in PHP

后端 未结 5 1760
自闭症患者
自闭症患者 2021-01-12 18:54

Having used Java for a long time my standard method for creating long strings piece by piece was to add the elements to an array and then implode the array.

         


        
5条回答
  •  长情又很酷
    2021-01-12 19:15

    One (subtle) difference is clearly visible when generating a character-seperated string:

    
    

    The first one will print a,b where the latter will print a,b,. So unless you're using an empty string as a seperator, as you did in your example, it's usually preferred to use implode().

提交回复
热议问题