Constants:
We use define() function or const keyword to define a constant. Only scalar data (boolean, integer, float, and string ) can be declared as constants. A resource can be declared as constant but it is not advisable because unexpected result could occur.
Unlike the variables we do not need to prepend $ sign before a constant. To print a constant we just need to mention the name of the constant.
PHP Constant Example:
<?phpdefine("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
Example:
<?php
const ab="324";const
ab="32"; echo ab; ?>Output:
324
As in the above example though we want to assign another value to the constant, but the output would be the first value of the variable.
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.