PHP Constants

A constant is an identifier whose value cannot be changed once it is declared in the program.

Rules for declaring a constant :
  •  Constants are case-sensitive and conventionally are always UPPERCASE.
  • A valid constant name always starts with a letter or an underscore(_) and is followed by any number of letters, numbers and underscores.
  • define() function is used to define a constant.
  • Constant can be accessed by writing its name or by calling constant() function if you want to obtain a constant value dynamically.
  • PHP constants are global and can be used throughout the program.

Syntax to declare a constant :

declare(name, value, case-insensitive);

Parameters :

name : name of the constant.

value : value of the constant.

case-insensitive : specifies whether the constant name would be case sensitive or not. By default its value is false.

Example :
<?php
				define(“MESSAGE”, “WELCOME TO OUR SITE”);
echo MESSAGE; 
echo constant(‘MESSAGE’);
			?>