define in PHP

Syntax of define in PHP

bool define(string name, mixed value[, int case_insensitive])

Defines a constant named name and sets its value to value. If case_insensitive is set and is true, the operation fails if a constant with the same name, compared case insensitively, is previously defined. Otherwise, the check for existing constants is done case sensitively. Returns true if the constant could be created, or false if a constant with the given name already exists

Example of define in PHP

define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.

define("GREETING", "Hello you.", true);
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."

// Works as of PHP 7
define('ANIMALS', array(
echo ANIMALS[1]; // outputs "cat"


Leave a Comment