constants, like variables, are used to temporarily store a value, but constants differ in many ways from variables.
Constant:
1. The data cannot be changed during program execution, and the scope of the constant is global.
2, the name of the constant is similar to the variable, just without the dollar sign "$". A valid constant name begins with a letter or underscore followed by any number of letters, numbers, or underscores.
3, generally in PHP constants are < span=""> and are divided into system constants and custom constants.
=================================================================================
< span="">We'll probably say that the knowledge in the back is going to be introduced.
1, __file__ Default constants, refers to the PHP program file name and path;
2, __line__ Default constants, refers to the number of PHP program lines;
3, the name of the __class__ class;
< span="">: Defines a constant by using the Define () function,
Its syntax format is: BOOL Define (String $name, mixed $value [, bool $case _insensitive = false])
Name: Specifies the names of the constants (uppercase).
Value: Specifies the values of the constants. (scalar and null are allowed only.) Scalar types are integer, float, String, or Boolean. It is also possible to define the type of a constant value as a resource (resource), but it is not recommended to do so, which can cause an unknown condition to occur. )
Insensitive: Specifies whether the name of the constant is case sensitive. True is not case-sensitive, and is case-sensitive if set to false. If this parameter is not set, the default value of false is case sensitive.
=================================================================================
Let's look at an example:
To understand this example, we will write constants later or directly with uppercase good.
We also pay attention to the constant printing:
1, when you want to print constants, you cannot enclose the constant in quotation marks, just like the example above;
2. Use the join operator to print constants
It is not easy to see the constants here, but there are many ways to use them, such as the most commonly used ones:
Define a constant, to determine the illegal call between pages, the specific point is that we do the homepage of the homepage, often the first page to separate the head and foot two files, this time we want to prevent someone illegal operation, directly call these 2 files, this time we directly in these 2 files separately add such a piece of code
Add the following code to the home page (the first page to introduce the head and foot files, the specific introduction of the method after the said, interested can own Baidu Google php file introduction)
The above is just a small example, later will say, or dig it yourself.
http://www.bkjia.com/PHPjc/743385.html www.bkjia.com true http://www.bkjia.com/PHPjc/743385.html techarticle constants, like variables, are used to temporarily store a value, but constants differ in many ways from variables. Constants: 1, it is not possible to change the data during program execution, the scope of the constant is full ...