PHP define () function
Examples
Define a case-sensitive constant:
<?php
define("GREETING","Hello you! How are you today?");
echo constant("GREETING");
?>
define("GREETING","Hello you! How are you today?");
echo constant("GREETING");
?>
Running instance »
Definition and Usage
define () function defines a constant.
Similar variables constant, except that:
- After setting the value of a constant can not be changed
- Constant names do not begin with a dollar sign ($)
- Scope does not affect access to the constants
- Constant value can only be strings and numbers
grammar
define (name, value, case_insensitive)
parameter | description |
---|---|
name | Required. Predetermined constant name. |
value | Required. A predetermined constant value. PHP7 support arrays, examples are as follows: <?php // PHP7+ 支持 define('ANIMALS', [ 'dog', 'cat', 'bird' ]); echo ANIMALS[1]; // 输出 "cat" ?> |
case_insensitive | Optional. Whether the provisions of the constant name is case sensitive. Possible values:
|
technical details
return value: | If successful it returns TRUE, on failure returns FALSE. |
---|---|
PHP version: | 4+ |
More examples
Example 1
The definition of a case-insensitive constants:
<?php
define("GREETING","Hello you! How are you today?",TRUE);
echo constant("greeting");
?>
define("GREETING","Hello you! How are you today?",TRUE);
echo constant("greeting");
?>
Running instance »
PHP Misc Reference Manual