- A constant is similar to a variable in the sense that you can store information in a keyword that can be used throughout your web page.
- However, the value of a constant cannot be changed, unlike a variable. It's literally "constant".
- It's also worth noting that constants are case-sensitive and are written in ALL CAPS by convention.
- The keyword 'define' is used in defining a constant in PHP:
define("TITLE", "Defining Constants");
- The first argument must be in quotes (string) and represents the name of the constant.
- The second argument is also a string and represents the value of the constant.
- The two arguments are seperated by a comma, enclosed within a bracket and ends with a semi-colon (;).
- To display a constant on your page, you can echo it using PHP , like this:
< ?php echo TITLE; ?>