Define a case-sensitive constant:
<?phpdefine ( "GREETING" , "Hello you! How are you today?" );echo constant ( "GREETING" ); ?>The define() function defines a constant.
Constants are like variables, except that:
After setting, the value of a constant cannot be changed.
Constant names do not require a leading dollar sign ($)
Scope does not affect access to constants
Constant values can only be strings and numbers
define( name,value,case_insensitive )
parameter | describe |
---|---|
name | Required. Specifies the name of the constant. |
value | Required. Specifies the value of the constant. PHP7 supports arrays, examples are as follows:<?php// PHP7+ supports define('ANIMALS', [ 'dog', 'cat', 'bird']); echo ANIMALS[1]; // Output "cat"?> |
case_insensitive | Optional. Specifies whether constant names are case-sensitive. Possible values: TRUE - case insensitivity FALSE - Default. Case sensitive |
Return value: | Returns TRUE if successful and FALSE if failed. |
---|---|
PHP version: | 4+ |
Define a case-insensitive constant:
<?phpdefine ( "GREETING" , "Hello you! How are you today?" , TRUE );echo constant ( "greeting" ); ?>