问题:
I am wondering, What is the proper way for inserting PHP variables into a string?我想知道,将 PHP 变量插入字符串的正确方法是什么?
This way:这边走:
echo "Welcome ".$name."!"
Or this way:或者这样:
echo "Welcome $name!"
Both of these methods work in my PHP v5.3.5
.这两种方法都适用于我的PHP v5.3.5
。 The latter is shorter and simpler but I'm not sure if the first is better formatting or accepted as more proper.后者更短更简单,但我不确定第一个是更好的格式还是被接受为更合适。
解决方案:
参考一: https://stackoom.com/question/NWMn参考二: PHP - concatenate or directly insert variables in string