问题
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