[Previous] [Contents] [Next]


Constants

Constants associate a name with a simple, scalar value. For example, the Boolean values true and false are constants associated with the values 1 and 0, respectively. It's also common to declare constants in a script. Consider this example constant declaration:

define("pi", 3.14159);

// This outputs 3.14159
echo pi;

Constants aren't preceded by a $ character; they can't be changed once they have been defined; they can be accessed anywhere in a script, regardless of where they are declared; and they can only be simple, scalar values.

Constants are useful because they allow parameters internal to the script to be grouped. When one parameter changes-for example, if you define a new maximum number of lines per web page-you can alter this constant parameter in only one place and not throughout the code.


[Previous] [Contents] [Next]