PHP constants store fixed values that cannot be changed once defined. They are ideal for configuration values that remain the same throughout script execution.
define()$ symbol is used
// Basic syntax for defining a constant in PHP
define(name, value, case_insensitive);
// Defining and using a constant
<?php
define("SITE_NAME", "MyWebsite");
echo SITE_NAME;
?>
MyWebsite
// Example of a case-insensitive constant (deprecated)
<?php
define("GREETING", "Welcome!", true);
echo greeting;
?>
Simulate how PHP handles constants. Try defining a constant and then try to change its value.
Think of constants as locked labels in your application—once set, every part of your code can read them but never modify them.
constant.phpdefine()