|The PHP constant is very similar to a PHP variable in that it is used to store a value but, unlike a variable, the value cannot be changed. It is called a constant because; you guessed it, it stays constant throughout the PHP program. By using a constant you "lock in" the value which prevents you from accidentally changing it. |
Secondly, if you want to run a program several times using a different value each time, you do not need to search throughout the entire program and change the value at each instance. You only need to change it at the beginning of the program where you set the initial value for the constant.
Let's take a look at an example where we use the define function to set the initial value of a constant to the state in the US that a business is located in. Then we can use this constant in an accounting program.
In the example above, the define function begins with the function name define followed by parenthesis. Within the parenthesis are the name of the constant and the value to be assigned to the constant. Both are enclosed within quotation marks and separated by a comma. This is all followed by a semicolon.