Php - Define (Global Constant)

> Procedural Languages > Php

1 - About

See define

3 - Example

  • Define
define('MY_ENV', getenv('MY_ENV'));
  • Defined
defined('MY_ENV')
  • Get
# Static
MY_ENV
# or Dynamic
constant('MY_' . 'ENV');
Advertising

4 - case-sensitivity

define("CONSTANT", "Hello world."); // The third parameter defaults to FALSE, meaning that the constant is case-sensitive. 
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.
 
define("GREETING", "Hello you.", true); // TRUE = case-insensitive. 
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."