Home >Backend Development >PHP Tutorial >Detailed explanation of the difference between '$$' in $$str in php
This article mainly shares with you the detailed explanation of the difference between "$$" in $$str in PHP. This writing method is called variable Variable variables are sometimes used Names are very convenient. That is, the variable name of a variable can be set and used dynamically. An ordinary variable is set by declaration, for example:
0834c2747917e2799e37ae8d59ad3b85
A variable variable obtains the value of an ordinary variable as the variable name of the variable variable. In the above example, hello can be used as a variable variable after using two dollar signs ($). For example:
eb5b7cf33180eb14df8d3b9c44df62a5
At this time, two variables are defined: the content of $a is "hello" and the content of $hello is "world". Therefore, it can be expressed as: 9f2863c794c2380c7a0d7058075bc9cd
<?php
echo "$a $hello";
?>
They will all output: hello world.
To use mutable variables with arrays, an ambiguity must be resolved. This is when writing $$a[1], the parser needs to know whether it wants $a[1] as a variable, or whether it wants $$a as a variable and extracts the variable with index [1] value. The syntax to solve this problem is to use ${$a[1]} for the first case and ${$a[1]} for the second case
${$a}[1].
Related recommendations:
The above is the detailed content of Detailed explanation of the difference between '$$' in $$str in php. For more information, please follow other related articles on the PHP Chinese website!