PHP Constant


 

PHP Constant

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.

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

 

Ads