Define
define is used to define a constant, which is also global in scope. You can access it anywhere in the script without the scope of the control. Once a constant is defined, it can no longer be changed or undefined.
There are a lot of similarities between constants and variables, so it's easy to confuse; Let's look at the differences between constants and variables:
A constant value cannot be changed after it has been specified
When you set a constant, you do not need to precede the "$" symbol
Constants can be accessed by domains of all scopes
The value of a constant can only be "strings [string]" and "numbers [number]"
The syntax format for define is as follows:
Define (name,value,case_insensitive)
parameter |
|
name |
|
value |
|
case_insensitive |
|
Specify a constant (case-sensitive) with the sample code as follows:
<?phpdefine ("greeting", "How is you today?"); ECHO constant ("greeting");? >
Output the following result:
How is you today?
Specify a constant (case-insensitive) with the sample code as follows:
<?phpdefine ("greeting", "How is you today?", TRUE); Echo constant ("greeting"); >
Output the following result:
How is you today?
Defined
The defined is used to detect that a constant is undefined and returns true if the constant exists, otherwise false.
The syntax format for defined is as follows:
Defined (name)
Parameters |
Description |
Name |
Necessary parameters. Specifies the name of a constant object |
The sample code is as follows:
<?phpdefine ("greeting", "How is you today?"); echo defined ("greeting");? >
Output the following results:1
The defined tag of the thinkphp template engine is used to determine whether a constant has been defined.
Defined tag usage is as follows:
<present name= "Constants" > What to Output </present>
Use the defined tag in the template/tpl/default/index/display.html as follows:
<defined name= "site_name" > website name:{*site_name}</defined>
If the judgment is not defined, you can use:
<notdefined name= "Site_Name" >{*site_name} does not exist live undefined </notdefined>