May 2003
Intermediate to advanced
592 pages
14h 28m
English
Constants are a specific data type in PHP which, unlike variables, retain their initial value throughout the course of a script. In fact, you cannot change the value of a constant once it has been set.
To create a constant, you use the define() function instead of the assignment operator (=) used for variables.
define ('NAME', 'value');
Notice that, as a rule of thumb, constants are named using all capitals, although this is not required. Most importantly, constants do not use the initial dollar sign as variables do (because, technically, constants are not variables).
Printing constants requires one of two techniques:
echo 'Hello, ' . NAME;
or
echo 'Hello, ', NAME;
You cannot print constants using echo "Hello, NAME" as ...
Read now
Unlock full access