There are many quantities that do not change in PHP. They are called constants. This time we will learn about the definition, use, naming and differences of constants from variables. Follow the editor to learn.
1. Concept
Constants are used to temporarily store values and will only exist when we execute the program.
2. Define and use
define('常量名称',常量值)
or
define("常量名称",常量值)
Constant naming:
and Variables can also only contain letters, numbers, and underscores, and must start with letters or underscores, not numbers;
Constant names are usually uppercase;
Customized constants are strictly case-sensitive.
3. The difference between constants and variables
$ ), there is a
$ symbol in front of the variable;
define() function;
4. Predefined constants
Predefined constants: Constants that have been defined in the PHP kernel and can be used directly. Magic constant: It is a predefined constant starting with__. The value is different depending on the location of the code, so it is called a magic constant.
php video tutorial"
The above is the detailed content of Understand php constants in one minute. For more information, please follow other related articles on the PHP Chinese website!