Learn what constants are in PHP and how to define them using the define() function. This guide covers constant usage, syntax, and case sensitivity with examples.
define()
.<?php
define("SITE_NAME", "My Awesome Site");
echo SITE_NAME; // Output: My Awesome Site
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>PHP - Contants</title>
</head>
<body>
<?php
// define(name, value, case-insensitive)
// case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false
define("GREETING", "Welcome to Department of CS & IT!");
function myTest() {
echo GREETING;
}
myTest();
?>
</body>
</html>
[1] “define,” PHP Manual. [Online]. Available: https://www.php.net/manual/en/function.define.php. [Accessed: Apr. 29, 2025].