PHP Constant

Solve your problems or get new ideas with basic brainstorming

Get Started. It's Free
or sign up with your email address
Rocket clouds
PHP Constant by Mind Map: PHP Constant

1. What is that?

1.1. A constant is an identifier (name) for a simple value. The value cannot be changed during the script.

1.2. A valid constant name starts with a letter or underscore (no $ sign before the constant name).

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

2. Set a PHP Constant

2.1. To set a constant, use the define() function - it takes three parameters: The first parameter defines the name of the constant, the second parameter defines the value of the constant, and the optional third parameter specifies whether the constant name should be case-insensitive. Default is false.

2.2. The example below creates a case-sensitive constant, with the value of "Welcome to!": <?php define("GREETING", "Welcome to!"); echo GREETING; ?> Will result : "Welcome to!"