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:
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.
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)
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;
?>
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning