当我想在字符串中使用变量值时,我将它们与 . (点)运算符。
我看到有些人在字符串中使用 {$variable}。
所以..我的例子:
"my name is ".$variable
一些人使用它:
"my name is {$variable}"
以上两个例子有什么区别?
最佳答案
当您想将字符串附加到字符串中变量中的值时使用它。
$variable = 'hack';
// now I want to append 'ed' to $variable:
echo "my name is {$variable}"; // prints my name is hack
echo "my name is {$variable}ed"; // prints my name is hacked
echo "my name is $variable"; // prints my name is hack
echo "my name is $variableed"; // Variable $variableed not defined.
关于php - {$variable} 在 PHP 中如何工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5138306/