PHP - concatenate or directly insert variables in string

前端 未结 14 2712
無奈伤痛
無奈伤痛 2020-11-22 04:45

I am wondering, What is the proper way for inserting PHP variables into a string?

This way:

echo \"Welcome \".$name.\"!\"
         


        
14条回答
  •  天命终不由人
    2020-11-22 05:22

    You Should choose the first one. They have no difference except the performance the first one will be the fast in the comparison of second one.

    If the variable inside the double quote PHP take time to parse variable.

    Check out this Single quotes or double quotes for variable concatenation?

    This is another example Is there a performance benefit single quote vs double quote in php?

    I did not understand why this answer in above link get upvoted and why this answer got downvote.

    As I said same thing.

    You can look at here as well

    What is faster in PHP, single or double quotes?

提交回复
热议问题