How to define a constant in PHP?

While variables make use of the operator ‘=’, constants instead are defined by making use of the define() function. When defining a constant it is important to always start the value with a letter or with an underscore (_), followed by the actual value which can be composed of any desired number of letters, numbers or underscores. The value is entered between the brackets and starts with the constant name enclosed by double quotation marks and followed by a comma after which the value is entered. One could choose to set the third parameter $case_sensitive to TRUE or FALSE. This latter action is not recommended though. Important to recall when defining a constant is the fact a constant can only be defined once. To verify the existence of yet another similar constant one could make use of the defined() function.



Was this useful?