PHP大括号,这段代码的含义是什么
我有这段代码(用于从数据库获取查询,在 MyBB 源中):
$query = "SELECT ".$fields." FROM {$this->table_prefix}{$table}";
我的问题是: < 的含义是什么代码>{$表}? $table 和 {$table}
之间有什么区别({}
的含义是什么)?
谢谢 ...
I have this code (for getting a query from database, in MyBB source):
$query = "SELECT ".$fields." FROM {$this->table_prefix}{$table}";
My question is: What's meaning of {$table}
? and what the difference between $table and {$table}
(what's meaning of {}
)??
Thank you ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
执行方式与使用大括号相同
在字符串中使用变量时(特别是对于那些没有语法高亮/色盲的人),
是可读代码的良好做法。样品:
Ta
Would execute identically to
Using curly braces is good practice for readable code when using variables within strings (especially for those without syntax hightlighting / color blindness).
sample:
Ta
这是在双引号内内联表达式的 PHP 语法。如果你有简单的表达式,比如变量名,你可以直接使用$table,而不需要考虑{}。
It's the PHP syntax for inlining expressions within double quotes. If you have simple expressions such as variable name, you can just use $table without bothering about {}.
大括号只是将变量名称与文本的其余部分(以及其他变量名称)隔离开来。通常,使用此语法是为了保持一致性;当变量遇到其他字母时,有时这是必要的,但许多程序员一直使用它,这样他们就不必考虑是否有必要。
请参阅文档。
The braces simply sequester the variable names from the rest of the text (and other variable names). Generally, this syntax is used for consistency's sake; it's sometimes necessary when you have variables that run into other letters, but many programmers use it all the time so that they never have to think about whether it's necessary.
See the documentation.