In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the php double $sign use case analysis of the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this php double $symbol use case analysis article, let's take a look.
Double $symbol refers to "variable variable", is a unique variable in PHP, that is, a variable takes the value of another variable as its name, and the syntax "$$variable name"; variable variables can be used to dynamically set and use the variable name of a variable.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
The double $symbol refers to a "variable", a unique variable in PHP that allows the name of a variable to be changed dynamically.
A variable is a variable that takes the value of another variable as its name.
A mutable variable gets the value of a normal variable as the variable name of the variable. Using this feature, we can dynamically set and use the variable name of a variable.
For example, we can set the value of $str:
$name = 'str'
So, we can use
Name replaces $str.
Name = 5
This code is equivalent to:
$str= 5
The use of variable variables
You only need to add at least two "$" symbols before the variable name.
Arrays use variable variables
In order to use the variable name of an array, you need to solve an ambiguity problem. That is, if you write $a [1], the parser needs to know whether you mean to use $a [1] as a variable or $an as a variable, and [1] refers to the index of the variable. The syntax to resolve this ambiguity is ${$a [1]} in the first case and ${$a} [1] in the second case.
Class properties can also be accessed through a variable property name. The variable attribute name is obtained from the access scope of the variable in which the call was made. For example, if your expression looks like this: $foo- > $bar, then the runtime will look for the variable $bar in the scope of the local variable, whose value will be used as a property name of the $foo object. You can also use $bar if it is an array.
Variable names cannot be used on super global array variables in PHP functions and classes. The variable $this is also a special variable that cannot be named dynamically.
Example
The following example uses a variable variable to change the name of a variable. The code is as follows:
Detailed explanation of examples:
First define two variables $str and $trans, and output the value of the variable $str, then use the variable to change the name of the variable $str, and finally output the value of the variable after the name has been changed
This is the end of the article on "case Analysis of the use of double $characters in php". Thank you for reading! I believe you all have a certain understanding of the knowledge of "case analysis of the use of double $characters in php". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.