In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
In this issue, the editor will bring you an introduction about the initialization and assignment of variables in php. The article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.
What is a variable?
In popular terms, a variable is a container. Depending on the type of variable, the size of the container is different, and the size of the data that can be stored is also different. The data stored in a variable is called a variable value.
Variables in PHP are represented by a dollar sign followed by the variable name. Variable names are case sensitive. In PHP, the naming convention for variables usually starts with a letter or underscore and consists of letters, numbers, and underscores. The variable name usually consists of English words that declare the meaning represented by the variable. Words and words are separated by _, or the first letter of the first word is lowercase, and then the first letter of each word is capitalized.
(free video tutorials to share: php video tutorials)
This kind of naming is called hump naming. Good naming conventions help to improve the readability of our code.
For example:
Initialization of variables
The initialization of a variable is to set a default value (or required value) to the variable. During initialization, PHP allocates storage space to the variable and stores the address of the storage space where the variable value resides.
Although you don't need to initialize variables in PHP, it's a good habit to initialize variables. Uninitialized variables have default values for their types
The default value of a variable of ● Boolean type is FALSE
The default values for ● shaping and floating-point variables are zero
● string-type variables (for example, in echo) the default value is an empty string
The default value of the ● array variable is an empty array
Using an uninitialized variable issues an E_NOTICE error, but not when attaching a unit to an uninitialized array.
Relying on the default values of uninitialized variables will be problematic in some cases, for example, in the subsequent coding, we often need to include a file to the current file through include. If the two files have the same variable name, the variable value is not the default value we need. In addition, opening register_globals in PHP versions prior to 5.4.0 is a major security hazard. This configuration has been removed since PHP 5.4.0.
The way variables are assigned
There are two ways of passing values in PHP, namely, passing value assignment and reference assignment.
1. Transfer value assignment
Passing a value assignment is the default way of passing a value in PHP. That is, when the value of an expression is assigned to a variable, the value of the entire original expression is assigned to the target variable. This means that when the value of one variable is assigned to another, changing the value of one of the variables will not affect the other. Such as:
2. Reference assignment
Reference assignment means that the new variable simply references the original variable, and changing the value of the new variable will affect the value of the original variable, and vice versa. To use a reference assignment, simply add a & symbol to the variable (source variable) to be assigned, such as:
The & symbol is called the address character in C language. The variable saves the storage address of the variable value in memory. By taking the address character, the address of the variable value saved by one variable can be assigned to another variable. The values of two variables point to the same memory address, so when we change the value of one variable, the value of the other variable changes naturally.
It is important to point out that only variables with names can refer to assignments.
There is no explicit memory address in the expression (2407) because it is not stored in the variable, and it is not advisable to get the address stored in memory by taking the address character.
The above is the introduction of the initialization and assignment of variables in php shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, 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.