Constants are variables that except once they are defined they cannot be undefined or changed.
A constant is an identifier or a name.
The value cannot be changed during the script.
A valid constant in PHP can be start with letter or underscore.
Create a PHP Constant ?
To create a constant in PHP, use the ‘define ()’ function ‘const’ keyword.
PHP constant using define ()-
Syntax:
Define (name, value)
Parameters:
• name: Specifies the name of the constant.
• value: Specifies the value of the constant.
Let’s see the example to define PHP constant using define().
Output :
PHP constant using, const keyword-
(1) It is bit faster than define().
(2) It is always be case-sensitive.
Let’s see the example to define PHP constant using const keyword.
Output :
Note :
Unlike variables, constants are automatically global across the entire script.
PHP echo Statements
echo used to print output data to the screen.
The PHP echo Statement
The echo statement can be used with or without parentheses: echo or echo().
Output :