PHP define() function
Definition and usage
The define() function defines a constant.
Constants are similar to variables, except that:
After setting, the value of the constant cannot be changed
The constant name does not require a leading dollar Symbol ($)
Scope does not affect access to constants
Constant values can only be strings or numbers
Recommended tutorial:PHP Video Tutorial
Syntax
define(name,value,case_insensitive)
Parameter | Description |
---|---|
name | Required. Specifies the name of the constant. |
value | Required. Specifies the value of the constant. |
case_insensitive | ##Optional. Specifies whether constant names are case-sensitive. If set to true, it will not be case sensitive. Default is false (case sensitive). |
Example
Example 1 Define a case-sensitive constant:
<?php define("GREETING","Hello world!"); echo constant("GREETING"); ?>
Hello world!
<?php define("GREETING","Hello world!",TRUE); echo constant("greeting"); ?>
Hello world!
The above is the detailed content of How to use define in php. For more information, please follow other related articles on the PHP Chinese website!