In this article, you will learn how to create constants with the PHP define function.
PHP define Function
The define() function create a PHP constant.
A constant can store a value, but unlike a variable, once set, it cannot be changed while the program is running.
Constants specified with the define() function can be called from anywhere in the program.
On the other hand, there is a method using
const, which allows you to define constants that are only used within a class.
define($name, $value, [case-insensitive])
$name: The name of the constant.
$value: The value of the constant.
[case-insensitive]: If it is set to true, a constant is created with a case-insensitive names.
Default is false.
<?php // case-sensitive constant name define("TEXT", "Hello World!"); echo TEXT; echo "<br>"; // case-insensitive constant name define("TEXT", "Hello World!", true); echo text; ?>
Hello World! Hello World!