Changes

PHP Constants

5 bytes added, 14:45, 29 May 2007
Using a Variable as a Constant Name
The key point to understand here as that the argument passed through to ''constant()'' can be a string variable set to the name of the constant.
As always an example helps a great deal in understanding a concept. In the script below we define a constant called ''MY_CONSTANT''. We Next we create a string variable called constantName and assign it a value of ''MY_CONSTANT'' (i.e a string that matrches the constant name). We can then use this new variable as the argument to ''constant()'' to obtain the constant value of ''MY_CONSTANT'':
<pre>