PHP - concatenate or directly insert variables in string

前端 未结 14 2600
無奈伤痛
無奈伤痛 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:32

    I use a dot(.) to concate string and variable. like this-

    echo "Hello ".$var;
    

    Sometimes, I use curly braces to concate string and variable that looks like this-

    echo "Hello {$var}";
    

提交回复
热议问题