1. Variables:
1. Variables must start with $, followed by the variable name
Note: In general, in the syntax of "can appear" variables, as long as the $ symbol appears, followed by the next character, it will be recognized as a variable, even if the variable does not exist, for example: echo "RMB matches ¥ is like a sheep, dollar sign $ is like money"; output to the page is like money;
2. Defining a variable: directly assigning a value to a variable is a definition ($v1=1)
Note: js does not support the definition without assignment. In other words, assigning a value to a variable for the first time is even defining a variable.
3. Value:
1. Output: echo $v1 //Get the value of $v1 and output
2. Assign values to other variables: $v2=$v1 //Get the value of $v1 and assign it to $v2
3. Participate in the operation: $v3=$v1+3 //Get the value of $v1 and add it to 3
4. Determine whether the variable exists isset():
1. If it exists, it will return true. If it does not exist, it will return false. 1 is true and 0 is false.
2. A variable whose value is ull returns false
5. Modify the variable value:
1. Assign a value to a variable for the second time and later, even if the variable is modified
6. Delete unset():
1. It is to disconnect the reference relationship between the variable name and the data
For example: (unset($v1)) At this time, the data is not referenced by any variable name. The variable name $v1 does not refer to any data, they all exist
7. There are two ways to pass values between variables, one is pass by value and the other is pass by reference
Pass-by-value: refers to copying the data value (content) of a variable, and then assigning it to another variable. After the assignment, the two variables have nothing to do with each other (independent of each other)
Pass by reference: $v2=&$v1 plus & sign means copying the data value (content) of a variable, and then assigning it to another variable. Another variable is also determined by this relationship to point to a certain data and they are related to each other For example $v1++ $v2 is also ++
8. Variable variables:
Meaning: The so-called variable variable is the name of a variable, and it is a variable. It is a very special syntax of php - in other languages
In theory, mutable variables can be nested more, such as $$$def
9. The data types of predefined variables (super global variables) are all arrays:
Commonly used: $_GET, $_POST, $_SERVER, $_REQUEST, $GLOBALS, $_COOKIE, $_SESSION, .......... (about 10)
10. $_GET variable:
Often appear in the form: <form action=”abc.php” method=”get” >.....</form> This is called the form to submit data by get
Form 1: Note: Multiple choices are named in the form of arrays
Form two:
Form three:
Form four:
Note: Regardless of the data submitted by the form of get, the obtained data is the same
11. $_POST variable
Usually there is only one form:
2. Constants :
Meaning: The identifier naming rules used to store a data that will not change and do not want to change are all uppercase
1. Define the form:
define('constant name', 'constant value'):
const constant name = constant value; can only be used in the top-level code area For example:
2. Use constants:
1. Use the name directly
2.constant('constant name')
3. The difference between constants and variables:
1. The definition/use form is not required: constants do not need the $ sign
2. The degree of variability is different: the value of the constant cannot be changed, and the constant cannot be destroyed
3. Different scopes: constants have super-global scope (both inside and outside the function can be used directly)
4. Different types are available: constants can only store scalar types: int, float, string, bool
4. Judging whether the constant exists The judgment result is a Boolean value:
Common form: if ( defined (a constant name) == false ){ here you can define the constant; }
Also: $result = defined (a constant name); //result is true or false
5. All predefined constants can be used directly:
For example: M_PI (pi), PHP_OS (operating system), PHP_VERSION (php version number), PHP_INT_MAX (maximum integer value in php)
E.g:
6. Magic constants:
Meaning: A constant whose value will change with certain conditions (environment), constant in form and use, but the value will change
For example: for example (both two _): __DIR__ (the directory where the current web page file is located), __FILE__ (the current web page file), __LINE__ (the current line)
E.g: