June 2005
Intermediate
720 pages
20h 6m
English
Constants are a specific data type in PHP that, 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. Constants can be assigned any single value—a number or a string of characters.
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 special syntax as well:
define ('USERNAME', 'trout'); ...Read now
Unlock full access