{$variable} 在 PHP 中如何工作?
当我想在字符串中使用变量值时,我将它们与 . (点)运算符。
我看到有些人在字符串中使用 {$variable} 。
所以..我的例子:
"my name is ".$variable
有些人使用它:
"my name is {$variable}"
上面两个例子有什么区别?
When I want to use a variable value within a string, I connect them with . (dot) operator.
I see that some people use {$variable} within a string instead.
So..my example:
"my name is ".$variable
some people use it:
"my name is {$variable}"
What is the difference between above two examples?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您想要将字符串附加到字符串内变量的值时,可以使用它。
It's used when you want to append a string to the value in the variable inside a string.
也许一些例子可以解释括号和 .连接字符串的运算符。
假设您有一个变量保存某个值,即 $money,并且您想要显示该金额。
因此,如果您有花括号,那么您可以更清楚地告诉 PHP 您想要将哪个变量替换到字符串中。
现在看起来好多了。
Maybe some examples will explain the brackets and the . operator to concatenate strings.
Lets say you have a variable holding some value which is say $money and you want to display this amount.
So if you have curly braces then you can tell PHP which variable you want substituted into the string a lot more clearly.
Now that looks a lot nicer.