PHP variable interpolation vs concatenation [duplicate]

ぐ巨炮叔叔 提交于 2019-11-26 12:27:07

问题


This question already has an answer here:

  • Should I use curly brackets or concatenate variables within strings? 3 answers

What is the difference between the two following methods (performance, readability, etc.) and what do you prefer?

echo \"Welcome {$name}s!\"

vs.

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

回答1:


Whatever works best for you works... But if you want to go for speed use this:

echo 'Welcome ', $name, '!';

The single quotes tell PHP that no interpretation is needed, and the comma tells PHP to just echo the string, no concatenation needed.



来源:https://stackoverflow.com/questions/16790501/php-variable-interpolation-vs-concatenation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!