The Define () function defines a constant.
The purpose of the Define () function is to define a constant.
Constants are much like variables, except for the following differences:
constants [constant] have a lot in common with variables [variable], so it's easy to confuse; below, we enumerate the differences between the constants [constant] and the variable [variable]:
A constant ' s value cannot be changed the It is set
A constant value cannot be changed after it has been specified;
Constant names do not need a leading dollar sign ($)
When you set a constant, you do not need to precede the "$" symbol;
Constants can be accessed regardless of scope
Constants can be accessed by all ranges of domains;
Constant values can only be strings and numbers
The value of a constant can only be "string" and "digit [number]";
Syntax
Grammar
Define (name,value,case_insensitive)
Parameter Parameter |
Description Describe |
Name |
Required. Specifies the name of the constant Necessary parameters. Specify the name of the constant |
Value |
Required. Specifies the value of the constant Necessary parameters. Specifying the value of a constant |
Case_insensitive |
Optional. Specifies whether the constant name should be case-insensitive. If set to TRUE, the constant would be case-insensitive. Default is FALSE (case-sensitive) Optional parameters. Specifies whether the name of the constant is case-insensitive [case-insensitive]. If set to True, the letter is case-insensitive, and if set to false, the case is case-sensitive. The default value is: False |
Example 1
Case 1
Define a case-sensitive constant:
Specify a constant (case-sensitive):
Copy Code code as follows:
<?phpdefine ("Greeting", "Hello you! How to Are you today? "); ECHO constant ("greeting");? >
The output of the code above would be:
The above code will output the following result:
Copy Code code as follows:
Hello you! How are are you today?
Example 2
Case 2
Define a case-insensitive constant:
Specify a constant (case-insensitive):
Copy Code code as follows:
<?phpdefine ("Greeting", "Hello you! How to Are you today? ", TRUE); Echo constant (" greeting ");? >
The output of the code above would be:
The above code will output the following result:
Copy Code code as follows:
Hello you! How are are you today?
The defined () function checks whether a constant exists.
the defined () function is to check whether a constant exists.
Returns TRUE If the constant exists, or FALSE otherwise.
Returns true if the constant exists, or false if it does not exist.
Syntax
Grammar
Copy Code code as follows:
Parameter Parameter |
Description Describe |
Name |
Required. Specifies the name of the constant to check Necessary parameters. Specifies the name of a constant object |
Example
Case
Copy Code code as follows:
<?phpdefine ("Greeting", "Hello you! How to Are you today? "); echo defined ("greeting");? >
The output of the code above would be:
The above code will output the following result:
1