This article introduces the $ explanation of variable $ str in php, which is very simple and practical, with a simple example. If you need it, you can refer to it.
This article introduces the $ explanation of variable $ str in php, which is very simple and practical, with a simple example. If you need it, you can refer to it.
This method is called variable.
Sometimes it is convenient to use a variable name. That is to say, the variable name of a variable can be dynamically set and used. A common variable is set through declaration, for example:
<? Php $ a = "hello";?>
A variable obtains the value of a common variable as the variable name of the variable. In the preceding example, after using two dollar signs ($), hello can be used as a variable of variable. For example:
<? Php $ a = "world";?>
At this time, both variables are defined: $ a's content is "hello" and $ hello's content is "world ". Therefore, it can be expressed:
<? Phpecho "$ a $ {$ a}";?>
The following statement is more accurate and the same result is output:
<? Phpecho "$ a $ hello";?>
They all output: hello world.
To use variables in an array, you must solve an ambiguous problem. When writing $ a [1], the parser needs to know that $ a [1] is used as a variable, you still want $ a as a variable and retrieve the value of [1] In the variable. The syntax for solving this problem is to use $ {$ a [1]} For the first case and $ {$ a} [1] For the second case.
The above is all the content of this article. I hope you will like it.