variable Variable
Sometimes it is convenient to use variable variable names. That is, the variable name of a variable can be set and used dynamically. An ordinary variable is set by a declaration, for example:
<?php$a = "Hello";? >
A mutable variable gets the value of an ordinary variable as the variable name of the variable variable. In the example above, hello uses two dollar sign ($) and can be used as a variable variable. For example:
<?php$ $a = "world";? >
At this point, two variables are defined: $a content is "hello" and $hello content is "world". Therefore, it can be expressed as:
<?phpecho "$a ${$a}";? >
The following wording is more accurate and will output the same result:
<?phpecho "$a $hello";? >
They all output: Hello world.
To use mutable variables with arrays, you must address an ambiguous question. This is when you write the $ $a [1], the parser needs to know if you want to $a [1] as a variable, or you want $ $a as a variable and take out the value of the variable indexed to [1]. The syntax for solving this problem is to use ${$a [1] for the first case, and ${$a}[1 for the second case).
<?php$a = ' Hello '; $ $a = ' world '; echo "$a ${$a}";
In the second sentence of the above code, we are using a variable of two dollar sign, then here this variable is our variable variable. The first sentence begins with a detailed explanation:
In our first sentence, we define an A variable whose value is hello. The second sentence we are: (since the discovery of the dollar sign has a special meaning, so I explained in the comments ...) )
$ $a = ' world ';//Here Our $ $a is mutable variable; the $ $a here represents $ (the value of $a), so what does that mean? Is our $ A value here a hello? then $ $a means to replace $ A with his value, then it's $hello. So that means $hello= ' world '; do you understand? Is our $ A not hello value? then $ $a, where $ A is not Hello, if you replace $ A with Hello that's not $hello then it means that the value of $hello equals the world, so to speak.
echo "$a ${$a}";
Need to add curly braces: {} If you do not add will be output variable name, we try to understand, it will be incorrect, in fact, the above code and the following code is the same:
<?php$a = ' Hello '; $ $a = ' world '; echo "$a $hello";? >