Constantly Remaining Constant
Constants are special types of variables that recieve a value and from then on can no longer be changed. this type of variable has a special place in PHP. It is normailly used when you have something that needs to be contained in a variable that iwll never change in your script, or has the potential of bing overwritten accidentially, and you wish to prevent aht from happening.
Many of the programmers in the PHP community borrow a syntax from the "C" programming language when defining a constant. That syntax is to name the constant variable in all capital letters like so.
- A constant with a string value:
- A constant with a number value:
<?php define('YOURCONSTANT', 'your_string_value') ?>
<?php define('YOURNUMBERCONSTANT', 100000) ?>
Naming your constants with this naming convention will help you and other programmers distinguish your constants from other variables and text. When you call your constant, like in an echo statement you do not call it with a dollar sign in front of it like you do with other variable types. This is another significant difference between constants and other types of variables within PHP.
<?php echo YOURCONSTANT ?>
The output for this echo statement will be, "your_string_value" depending on what you placed as your value. Remember that strings need to be within quotes, and numbers need not be.