Search

PHP constants

A constant is an identifier (name) for a simple value. As the name suggests, that value cannot change during the execution of the script Constants are case-sensitive. By convention, constant identifiers are always uppercase.

  • Constants variable are automatically global and can be used across the entire script.
  • A valid constant variable name starts with a letter or underscore

Syntax

define(identifier,value,case-insensitive);

To create a constant variable , use the define() function.

Example

// Valid constant names
define("FOO",     "something");
define("FOO2",    "something else");
define("FOO_BAR", "something more");

// Invalid constant names
define("2FOO",    "something");

Parameters

ParametersDescription
identifierThis parameter specifies the name of the constant
valueThis parameter specifies the value of the constant
case-insensitiveThis parameter contain bool value the constant name should be case-insensitive. Default is false

Stack Overlode is optimized Tutorials and examples for learning and training. Examples might be simplified to improve reading and learning and understand. Tutorials and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using Stack Overlode, you agree to have read and accepted our terms of use, cookie and privacy policy.