Constants must be defined before they are used, or the program execution will fail. Use the Define () function in the PHP tutorial to define constants.
1. Syntax format: define ("Constant name", "Constant value");
For example: Define ("php360", "Perfect php");
Here's an example:
The Define () function defines a constant.
Constants are similar to variables, except that:
After setting, the value of the constant cannot be changed
Constant name does not need to start with dollar sign ($)
Scope does not affect access to constants
A constant value can only be a string or a number
Grammar
Define (name,value,case_insensitive) parameter description
Name is required. Specifies the name of the constant.
Value is required. Specifies the value of the constant.
Case_insensitive required. Specifies whether the name of the constant is case sensitive.
If set to true, the case is not sensitive. The default is False (case sensitive).
*/
Define ("greeting", "Hello world!");
ECHO constant ("greeting");
/*
Running this code will output hello world! in the browser. The result.
2, the constant naming rules: start with a letter or underscore, followed by any letter, number, underline.
3. The difference between constant and variable:
(1) A constant is preceded by a $ symbol, and the variable must begin with a $ symbol.
(2) Constants can only be defined with the Define () function and cannot be defined by an assignment statement.
(3) Constants can be defined and accessed anywhere, regardless of the rules of the variable scope.
(4) Once a constant is defined, it cannot be redefined or de-defined, and the value cannot be changed, and the value of the variable can change at any time.
(5) The value of a constant can only be scalar, that is, integer, float, string 3 types */
http://www.bkjia.com/PHPjc/632320.html www.bkjia.com true http://www.bkjia.com/PHPjc/632320.html techarticle constants must be defined before they are used, or the program execution will fail. Use the Define () function in the PHP tutorial to define constants. 1, Syntax format: Define (constant name, constant value); For example: ...