PHP – Constants

A constant is an identifier (name) for a simple value. The value cannot be changed during the script.

A valid constant name starts with a letter or underscore (no $ sign before the constant name).

Unlike variables, constants are automatically global across the entire script.

To set a constant, use the define() function.

Statement:

define(“GREETING”, “Welcome to W3Schools.com!”, true);

define(“constant name”, “constat value”, case-insensitive true/false);


<?php

// define a case-insensitive constant
define("GREETING", "Welcome to W3Schools.com!", true);
echo GREETING;
echo "<br>";
// will also output the value of the constant
echo greeting; // case-insensitive

?>