PHP - concatenate or directly insert variables in string

前端 未结 14 2689
無奈伤痛
無奈伤痛 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条回答
  •  猫巷女王i
    2020-11-22 05:15

    Do not concatenate. It's not needed, us commas as echo can take multiple parameters

    echo "Welcome ", $name, "!";
    

    Regarding using single or double quotes the difference is negligible, you can do tests with large numbers of strings to test for yourself.

提交回复
热议问题