Constants

clookid

203.***.***.***
1,860 days ago

Constants

Constants
Constants are much like variables, except you can't change them. You can declare them at the beginning of a script and use them instead of any fixed number that you can't be sure will never change. PHP sets some constants for you, like TRUE, FALSE and NULL.

To create a constant, you use the define() function. Constants can be named just like variables, and they can store anything a variable can except an array.

PHP code:

define("MY_CONSTANT", "Hello World");
echo MY_CONSTANT; // prints "Hello World"



A lot of mathematical constants are also preset for you when PHP starts up, namely M_PI for pi. Read the "Mathematical functions" section of the PHP manual for the complete list.