What are PHP constants
The so-called constants are quantities that cannot be changed. Once a PHP constant is defined, it cannot be changed or undefined.
php constants are usually used to store data that does not change and is not expected to change. The data can only be data of four scalar data types: integer (integer), floating point (decimal) ), string, Boolean (true/false).
Naming rules for php constants
The naming rules for php constants are similar to the naming rules for php variables but not exactly the same.
php constant names must be composed of letters, underscores, and numbers;
cannot start with a number;
Whether it is case-sensitive or not is specified when defining;
All letters are capitalized when naming (such as: PI);
How to define PHP constants
php constants are defined using the define() function, define() function There are two required parameters and one optional parameter.
The first parameter specifies the name of the constant, also called an identifier;
The second parameter specifies the value of the constant, which is a scalar data type that does not want to be changed;
The third parameter is an optional parameter, used to specify whether the constant name is case-sensitive. If TRUE, constant names are case-insensitive; if FALSE (the default), they are case-sensitive.
Recommended tutorial: PHP tutorial
The above is the detailed content of What data types can the data stored in PHP constants be?. For more information, please follow other related articles on the PHP Chinese website!