PHP Constants
Constants are like variables except that once they are defined they cannot be changed or undefined.
Create a PHP Constant
To create a constant, use the define() function.
Syntax
define(name, value, case-insensitive)
The parameters are as follows:
- name: It specifies the constant name.
- value: It specifies the constant value.
- case-insensitive: Specifies whether a constant is case-insensitive. Default value is false. It means it is case sensitive by default.
Create a constant with a case-insensitive name:
PHP Constant Arrays
In PHP7, you can create an Array constant using the define() function.
Create an Array constant:
Constants are Global
Constants are automatically global and can be used across the entire script.
Example
This Example uses a constant inside a function, even if it is defined outside the function: