Php constants and php Constants
The define () function is used to define constants. Once a constant is defined, it cannot be changed or undefined.
Example of defining constants:
<? Phpdefine ("CONSTANT", "codenong tutorial"); echo CONSTANT;?>
Run
Constant names and any other PHP labels follow the same naming rules. A valid constant name starts with a letter or underline followed by any letter, number, or underline.
Constants are case-sensitive by default, and constant identifiers are always capitalized. This value cannot be changed during script execution.
Differences Between Defining constants and variables:
- No dollar sign before a constant ($)
- Constants can only be defined using the define () function, but cannot be defined using the value assignment statement.
- Constants can be defined and accessed anywhere, regardless of the variable range rules.
- Once defined, a constant cannot be redefined or undefined.
- The constant value can only be a scalar.
PHP has a large number of predefined constants. For more information, see the PHP manual.
Address: http://www.manongjc.com/php/php_constant.html
Related reading:
Php str_pad () function to populate the string with the specified length
Analysis and explanation of php str_replace () string replacement function
The php str_ireplace () function replaces characters in strings with case-insensitive characters.
The php str_getcsv () function parses the CSV string into an array.