Now that you have been introduced to variables, it is time to learn about 'fixed' variables, or constants. Constants are variables that are assigned a semi-permanent or permanent value. For example, you might want to define a constant variable to hold sales tax percentage. Sales taxes tend to stay the same over an extended period of time, however, sales taxes might go up (or down). A constant allows you to define your fixed variable in one place. If there is a change, you only need to update your constant definition and your code will continue to work.
Define constants using the define function, like so:
define("SALES_TAX", .07859358);
define("TEACHER", "Mr. Chagoyan");
define("PI", 3.1415926535);
It is good practice to use all capitals for your constant names for easy identification.
Here's another example: constants.php |