If the string has a variable, you need to output the value of the variable.
还有一种方式:
$a=' hello';echo "my name is {$a}";
有时候在动态使用变量名的时候也会有这两种方式:
$this->{$property} = $argument
或者$this->$property
这两种效果都是一样的,但是到底有啥区别呢?
Reply content:
If the string has a variable, you need to output the value of the variable.
还有一种方式:
$a=' hello';echo "my name is {$a}";
有时候在动态使用变量名的时候也会有这两种方式:
$this->{$property} = $argument
或者$this->$property
这两种效果都是一样的,但是到底有啥区别呢?
There is no big difference, with curly braces just handy for PHP parsing when you look for variables. For example, you can try:
$a = "hello";echo "$aworld";echo "{$a}world";
That is, when a variable name is the previous part of another variable name, add {} to get what you want.
$a='hello ';$aword=' word';echo "my name is $aword"; //my name is wordecho "
";echo "my name is {$a}word"; //my name is hello word
Curly braces {} can only be used in double quotes when using echo
Similar to bash, differentiate variables and strings
//只是为了区别变量而已,如下:$a = "he";//如果这样,你的变量$allo是不存在的echo "$allo";//所以,需要加一个定界符来加区分echo "{$a}llo";//echo hello//这种情况只在双引号后中有用。如果你需要打印的变量前面没有英文或容易混淆变量的情况下可以不用的。