Core PHP PHP

PHP Constants

PHP Constants or Constant in PHP

 

A constant is an identifier or name for a value. As the name, the value of variable cannot be change during the execution of the script. Constants are case-sensitive. Constant identifiers are always uppercase.

Rule of a constant:

  1. Constant name starts with letter
  2. Constant name starts with underscore followed by number of letters
  3. Constant can’t start with number or integer

 

<?php

// Valid constant
define(“CONSTANT”, “Hello India This is constant”);
define(“CONSTANT2”, “Hello India This is constant Type 2”);
define(“CONSTANT_NAME”, ” Hello India This is constant Type Other”);

// Invalid constant
define(“2CONSTANT”, “Wrong / Invalid constant”);
define(“2 CONSTANT”, ” Wrong / Invalid constant Type 2″);

// This is valid, but should be avoided:
// that will break your script
define(“__CONSTANT__”, ” Hello India This is constant”);

?>

Leave a Reply

Your email address will not be published. Required fields are marked *