1. define the constant define ("constant", "hello world .");
Constants can only contain scalar data (boolean, integer, float, and string ).
When calling a constant, you only need to obtain the constant value with a simple name, instead of adding the "$" symbol, such as echo constant;
Note: constants and (global) variables are in different namespaces. This means that for example, true and $ true are different.
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 is required. Specifies the name of a constant.
Value is required. Specifies the value of a constant.
Case_insensitive is required. 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
Example 1
Defines a case-sensitive constant:
<? Php Tutorial
Define ("greeting", "hello world! ");
Echo constant ("greeting ");
?> Output:
Hello world! Example 2
Defines a case-insensitive constant:
<? Php
Define ("greeting", "hello world! ", True );
Echo constant ("greeting ");
?> Output:
Hello world!
2. Common variable $ a = "hello ";
3. Variable variable (using two dollar signs ($ ))
$ A = "world ";
Both variables are defined:
$ A's content is "hello" and $ hello's content is "world ".
Therefore, it can be expressed:
Echo "$ a $ {$ a}"; or echo "$ a $ hello"; both outputs: hello world
To use variables in an array, you must solve an ambiguous problem. When writing $ a [1], the parser needs to know that $ a [1] is used as a variable, you still want $ a as a variable and retrieve the value of [1] in the variable. The syntax for solving this problem is to use $ {$ a [1]} for the first case and $ {$ a} [1] for the second case.