If a string has a variable, the value of the variable needs to be output. {Code ...} another way: {code ...} sometimes there are two ways to dynamically use the variable name: $ this-& amp; gt; {$ property} $ argument or $ this-& amp; gt; $ property has the same effect... if a string has a variable, the value of the variable needs to be output.
Another method is as follows:
$a=' hello';echo "my name is {$a}";
Sometimes there are two ways to dynamically use the variable name:
$this->{$property} = $argument
Or$this->$property
The two effects are the same, but what are the differences?
Reply content:If a string has a variable, the value of the variable needs to be output.
Another method is as follows:
$a=' hello';echo "my name is {$a}";
Sometimes there are two ways to dynamically use the variable name:
$this->{$property} = $argument
Or$this->$property
The two effects are the same, but what are the differences?
There is no big difference. Using curly brackets is just to help PHP identify variables during parsing. For example, you can try:
$a = "hello";echo "$aworld";echo "{$a}world";
That is to define the variable. When a variable name is the first 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
When echo is used, braces {} can only be used in double quotation marks.
Similar to bash, variables and strings are distinguished.
// Just to differentiate variables, as follows: $ a = "he"; // If so, your variable $ allo does not exist echo "$ allo"; // Therefore, you need to add a separator to distinguish echo "{$ a} llo"; // echo hello // This is only useful after double quotation marks. If the variables you want to print are not preceded by English or are easy to confuse with variables, you do not need to use them.