What are some basic PHP knowledge records? PHPdefine () function? Define and use the define () function to define a constant. Constants are similar to Variables. The difference is that, after a constant is set, the constant value cannot change the dollar sign ($) that does not need to begin with the constant name) the scope does not affect constant access. the constant value can only be a string or number syntax :? De PHP basic knowledge record
?
PHP define () function
?
Definition and usage
The define () function defines a constant.
Constants are similar to variables, except that:
- After setting, the constant value cannot be changed.
- The constant name does not need to start with the dollar sign ($)
- The scope does not affect constant access.
- A constant value can only be a string or number.
Syntax:
?
define(name,value,case_insensitive)
?
Parameter description
| Name |
Required. Specifies the name of a constant. |
| Value |
Required. Specifies the value of a constant. |
| Case_insensitive |
Optional. Specifies whether the constant name is case sensitive. If it is set to true, it is not case sensitive. The default value is false (case sensitive ). |
Example 1
Defines a case-sensitive constant:
define("GREETING","Hello world!");echo constant("GREETING");?>
Output:
Hello world!
Example 2
Defines a case-insensitive constant:
define("GREETING","Hello world!",TRUE);echo constant("greeting");?>
Output:
Hello world!
?
?