PHP Constants
Summary: A constant is a name or an identifier for a simple value. A constant value cannot change during the execution of the script. By default a constant is case-sensitive. By convention, constant identifiers are always uppercase.
A constant is a name or an identifier for a simple value. A constant value cannot change during the execution of the script. By default a constant is case-sensitive. By convention, constant identifiers are always uppercase. A constant name starts with a letter or underscores, followed by any number of letters, numbers, or underscores. PHP constants can be defined in 2 ways:
- Using define() function
- Using const keyword

PHP constants follow the same PHP variable rules. For example, it can be started with a letter or underscore only.
Conventionally, PHP constants should be defined in uppercase letters.
constant() function:
As indicated by the name, this function will return the value of the constant.
This is useful when you want to retrieve the value of a constant, but you do not know its name, i.e. It is stored in a variable or returned by a function.
Let's see the syntax of define() function in PHP.
define(name, value, case-insensitive)
- name: specifies the constant name
- value: specifies the constant value
- case-insensitive: Default value is false. It means it is case sensitive by default.
Lets see the example (case-insensitive) to define PHP constant using define().
<?php
define("EASYTOLEARNING", "Welcome to Easytolearning.com!");
echo EASYTOLEARNING;
?>
The example below creates a constant with a case-insensitive name:
<?php
define("EASYTOLEARNING", "Welcome to easytolearning.com!", true);
echo easytolearning;
?>
