How to use const in php
This article introduces the relevant knowledge of "how to use const in php". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
const is a keyword in php, used to define constants, syntax "const constant name = constant value;";const keyword when defining constants, can only contain scalar data (bool, int, float, string). Once a constant is defined, it cannot be changed or undefined.
Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer
const is a keyword in php that defines constants.
In PHP, you can define a constant using either the const keyword or the define() function. The function define() allows a constant to be defined as an expression, while the const keyword has some limitations. Once a constant is defined, it cannot be changed or undefined.
Constants defined with the const keyword can only contain scalar data (bool, int, float, string). A constant can be defined as an expression or as an array. It is also possible to define resource as constant, but this should be avoided as it may have unpredictable results.
Constants have several characteristics compared to variables:
Constant without dollar sign ($);
Constants can only be defined with define() and const;
The scope of a constant is global;
Constants, once defined, cannot be redefined or undefined.
The const keyword defines the syntax for constants:
const constant name = constant value;
Examples:
"How to use const in php" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!