1. define the constant define (quot; constantquot;, quot; helloworld. quot;); constants can only contain scalar data (boolean, integer, floa... 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, which means that for example, true and $ true are different.
Definition and usage
The define () function defines a constant, which is similar to a variable. The difference is:
After the value is set, the constant value cannot be changed. the constant name does not need the dollar sign ($) at the beginning. the scope does not affect constant access. the constant value can only be a string or number.
Syntax
Define (name, value, case_insensitive) parameter description
Name is required. it specifies the name of a constant.
Value is required, specifying the value of a constant.
Case_insensitive is required to specify 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: define a case-sensitive constant:
Example 2: define a case-insensitive constant:
2. common variable $ a = "hello ";
3. 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. this is when you write $ a [1, the parser needs to know whether to use $ a [1] as a variable or $ 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.
Permanent address:
Reprint at will ~ Please bring the tutorial URL ^