Constants can be understood as the amount of constant values. Constants are defined and cannot be changed anywhere else in the script, a constant by the English alphabet. Underscores, and numbers, but numbers cannot be the first letter of a constant.
Use the # define () function in PHP to define constants, the syntax for the function is as follows:
Define (string constant_name,mixed value,case_sensitive=true)
There are two ways to get the value of a constant. One method is to get the value directly using the name of the constant, and the other is to take advantage of the constant () function, and the other is to use the constant () function and output it directly using the constant name. However, the function can dynamically output the values of different constants, which is more flexible and convenient.
The first gets its value directly with the name of the constant
<?PHP define ("test", "I am jack!"); echo test;?>
The results of the execution are as follows:
Another way to get a constant value code using the constant () function is as follows:
<?php define ("test", "I am jack!"); $JACKSTR = "Test"; ECHO constant ($JACKSTR);?>
The results of the execution are as follows:
Next, let's talk about uppercase and lowercase sensitive issues. Just now the declaration of the constant is set in uppercase and lowercase sensitive, we use the code to verify the see is not, in addition to enhance my memory
The code is as follows:
<?php define ("test", "I am jack!", true); echo Test;echo "\ n"; echo Test;echo "\ n"; echo Test;echo "\ n";?>
Let's look at the results of the output again.
You can find words that are not sensitive to uppercase and lowercase. Even if there is a difference between uppercase and lowercase, the output will still be the same.
Defining constants in advance is no different from using our custom constants. Common pre-defined constants such as the following:
Declaration and use of PHP constants