1 Version differences:
Const requires PHP version "5.3.0
Define can be compatible with PHP4,PHP5 and other versions
2 Definition of location differences:
Constants defined by the Const keyword are defined at compile time, so the const keyword definition constants must be at the top of the range
(meaning that constants cannot be defined within a function, within a loop, and within an if statement with a const)
The constants defined by the function define () are defined when the Define () function is executed, so you can use the Define () function to define constants anywhere within a function, within a loop, within an if statement, or wherever functions can be called.
3 differential support for value expressions:
Const-defined constants are defined at compile time, so many operators, such as arithmetic operators, bitwise operators, comparison operators, and so on, are not supported in expressions for constant values defined by the Const keyword
These operators define() can be used directly when defining constants in a function.
Define (' Define_var1 ', 1 << 1); // Const CONST_VAR1 = (1 << 1);//const does not support bitwise operators, PHP will report syntax errors
4 support differences in case sensitivity to characters:
Const keyword defines constant-size-sensitive
Define () can receive the 3rd parameter, which indicates that the case of the constant name is not sensitive if the argument is True
Define true ); Echo // Output: Codeplayer Echo // Output: Codeplayer Echo // Output: Codeplayer
Note: Using const makes the code easy to read, and const itself is a language structure, and define is a function. In addition, the const is much faster to compile than define.
The difference between const and define in PHP