I have been using PHP for a short time. I know that $ username represents a variable, and in many cases it is written like this. Today, I suddenly saw the format & amp; quot ;$ {username} & amp; quot; in one place, and I couldn't understand it. What is this $ {} used for? It's been a short time in googl... using PHP.
$usernameIs a variable, and in many cases it is written in this way.
Today, I suddenly saw
"${username}"This way of writing won't be understood in an instant.
This
${ }What is it used to do? This stuff does not know how to search in google. It cannot be searched.
Reply content:
I have been using PHP for a short time.$usernameIs a variable, and in many cases it is written in this way.
Today, I suddenly saw"${username}"This way of writing won't be understood in an instant.
This${ }What is it used to do? This stuff does not know how to search in google. It cannot be searched.
Reference: http://php.net/manual/en/language.var...
To solve an ambiguous problem, it is used in places where ambiguity may occur and clearly tells the compiler how to interpret the code.
// DaiJie has more than one explanation in the Code. The php interpreter does not know what is correct. $ C = array ('D' => 'E'); echo "{$ c} ['D']"; // Array ['D'] $ c = array ('D' => 'E'); echo "$ {c ['D']}"; // e
// The null code is also ambiguous. $ var = "hello"; $ var _ = "world"; echo "{$ var }_$ var _"; // hello _ world $ var = "hello"; $ var _ = "world"; echo "{$ var _} $ var _"; // world
Prevents future Variables
Brackets in variable names are used to increase priority.
$ Title = 1;
$ {"Title_default _". $ title} = "selected ";
Echo $ title_default_1;
// Variable writing