April 2026
Intermediate
1009 pages
34h 15m
English
Constants, unlike variables, always have the same value, which is defined once at the beginning. In PHP, you define it with the const keyword or—less commonly—with the define()function :
const constant = "value";define("Constant", "Value");
The constant can be accessed at any time using its name:
echo constant;
This outputs its value—in this case, the string value.
Alternatively, you can access constants using the constant(Name) function:
echo constant("constant");
This function is used if the constant name is only passed as a reference—for example, stored in a variable or as a parameter of a function:
$Name = "Constant"; constant($Name);
Unlike variables, constants do not have a $ sign. In addition, globally defined ...
Read now
Unlock full access