PHP Constants

In this tutorial you will understand the concept of 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).

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

How to create PHP constants:

define(namevaluecase-insensitive)

Parameters:

  • name: Specifies the name of the constant
  • value: Specifies the value of the constant
  • case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false

Example:

Note: Constants are automatically global and can be used across the entire script.

Example:

This is a simple and effective tutorial of creating PHP Constants. If you have any question, ask it at our Forum Section.