Define Function in PHP
In this article, we will discuss what is defined () function in PHP. The define function is one of the PHP. To define a constant, we have to use the define() function, and to retrieve the value of a constant, we have to simply specify its name.
syntax:
define(name, value, case-insensitive)
where:
- name: specifies the constant name
- value: specifies the constant value
- case-insensitive : Default value is false. It means it is case-sensitive by default.
Ex1:
<?php
define("MESSAGE", "Hello PHP User");
echo MESSAGE;
?>
Output:
Hello PHP user
Ex2:
<?php
define("MESSAGE", "Hello PHP User", true); //not case sensitive
echo MESSAGE;
echo message;
?>
Output:
Hello PHP User Hello PHP User
Ex3:
<?php
define("MESSAGE", "Hello PHP ", false); //case sensitive
echo MESSAGE;
echo message;
?>
Output:
Hello PHP
ERROR Notice : Use of undefined constant message assumed ‘message’.