define() - Defining Constants


How do you define a constant in PHP?

✍: FYIcenter


You can define a constant by using the define() function. Once a constant is defined, it can never be changed or undefined. For example:

define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a

Only scalar data (boolean, integer, float and string) can be contained in constants.

2007-02-27, 5348👍, 0💬