A constant is an identifier for a value that cannot change during the course of a script. Once a constant has a value, it remains through its execution lifetime. Constants can be user defined, or you can use some of the predefined constants that PHP always has available. Unlike simple variables, constants do not have a dollar sign before their name, and they are usually uppercase to show their difference from a scalar variable. Next, you’ll test the user-defined type.
1. Open a new file in your text editor and open a PHP block:
2. The function used to define a constant is called define(), and it requires the name of the constant and the value you want to give it. Here you define a constant called MYCONSTANT with a value of “This is a test of defining constants.”.
define(“MYCONSTANT”, “This is a test of defining constants.”);
3. Print the value of the constant and then close the PHP block: