Server Side/PHP

[PHP] define (Misc. Function)

DevES 2015. 7. 31. 07:43

Defines a named constant


bool   define  (  string   $name ,   mixed    $value    [  ,   bool    $case_insensitive    =    false   ]   )
Defines a named constant at runtime.

*Parameters

-name: the name of the constant.


-value: The value of the constant; only scalar and null values are allowed. Scalar values are integer, float, string or boolean values.


-case_insensitive: If set to true, the constant will be defined case_insensitive. The default behavior is case-sensitive; i.e. CONSTANT and Constant represent different values.

 

*Return value

-When it succeed, return true. On the contrary, return false.


Example:


<?php

define("CONSTANT", "Hello world.");

echo CONSTANT; // "Hello world."

echo Constant; // just output "Constant" with noticing issues.


define("GREETING", "Hello you.", true);

echo GREETING; // outputs "Hello you."

echo Greeting; //  outputs "Hello you."

?>