ProAnswers.org

How do you declare a constant using PHP?

How do you declare a constant using PHP?

Outside of a class definition, constants can be declared with the define function. The function has two arguments; the name of the constant (a string), and the value of the constant (any variable type).

Inside a class definition, constants can be declared with the const keyword. Type the word const, the name of the constant in the form of how it will be called later, an “equals sign,” then the desired value of the constant.

In both cases, here is an example.