PHP Constant
Posted on: February 13, 2010 at 12:00 AM
In this tutorial you will come to know about constant in php, . You can store any kind of value which is not intend to change like mathematical constants like value of pi, paths to files etc.

PHP Constants:

Constants are like any other variables to store information but the difference between the constant and a variable is value of constant can not be changed but the value of the variable can be changed at any point of time. You can store any kind of value which is not intend to change like mathematical constants like value of pi, paths to files etc.

Example:

<?php

define("pi",3.14);

echo "Output of pi is :".pi."<br/>";

echo "If we would like to print constant within \"\" sign output would be: pi <br/> ";

echo "Since pi is a constant, we need not to use '$' sign before constant";

?>

Output:

Output of pi is :3.14
If we would like to print constant within "" sign output would be: pi
Since pi is a constant, we need not to use '$' sign before constant

 

Related Tags for PHP Constant:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.