07 Jul PHP Constants
A constant once defined, cannot be undefined. A valid constant name starts with a letter or underscore (no $ sign before the constant name). PHP constants use the define() function for creating a constant.
Constant name starts with a letter or underscore, but they can’t be considered as a variable, since constant name once defined can’t be changed.
The define() function is used for creating a constant. Here’s the syntax:
1 2 3 |
define(name, val, case-insensitive) |
Here,
- name is the constant name
- val is the value of the constant
- case-insensitive is for constant name insensitive.
The following is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<!DOCTYPE html> <html> <body> <?php define("RANKING", "ICC Rankings for Team!"); echo RANKING; ?> </body> </html> |
Here’s the output,
In the above example, we haven’t mentioned the case section, since the default is false. If you want a case-insensitive name, use true i.e
1 2 3 4 |
define("RANKING", "ICC Rankings for Team!", true); echo ranking; |
We used the define() function since it is used for creating a constant.
No Comments