且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

PHP:在双引号内使用变量

更新时间:2022-12-07 11:50:27

$imagebaseurl = 'support/content_editor/uploads/' . $name;

$imagebaseurl = "support/content_editor/uploads/{$name}";

请注意,如果使用双引号,也可以将上面的代码写为:

Note that if you use double quotes, you can also write the above as:

$imagebaseurl = "support/content_editor/uploads/$name";

尽管要养成在双引号中使用{$...}而不是仅在$...中使用的习惯,但是在某些情况下,您需要在字符串中插入变量,而对于PHP来说这并不明显,这是变量的一部分,哪一部分是字符串.

It's good though to get in the habit of using {$...} in double quotes instead of only $..., for times where you need to insert the variable in a string where it's not obvious to PHP which part is the variable and which part is the string.

如果要获得***性能,请使用带单引号的字符串连接.

If you want the best performance, use string concatenation with single quotes.