Differences and usage of variable constants

                  variable

1. Variables must start with $, followed by the variable name.

2. Unlike JS, it does not support 'define only without assignment'. Assignment is to make one variable name use another value;

3. Two methods of variables:

  1. isset(): Judging whether the variable name exists, returns 1-true if it exists, and returns 0-false if it does not exist. If the value of a variable is Null, it does not meet the variable definition rules, and it returns false.

  2.unset(): disconnect the "reference relationship" between the variable name and the data

4. Pass-by-value (pass-by-value/pass-by-reference)

  Pass-by-value: copy a data value (data) and assign it to another variable. After the assignment, the two are independent of each other

  Pass-by-reference: Copy and pass the reference relationship at the same time. Key symbol & Example: $a=1; $b=&$a

5. Variable variables

  refers to the name of a variable, which is another variable example:

        $v1 = "abc"; // this is a string variable whose content is the string " abc "

        $abc = 10; // This is a normal variable whose content is the number 10

             echo $$v1; // At this time, it is the so-called "variable variable"

    understanding of variable variables   

      1 , whenever the $ sign appears, it may be understood as a variable

 

      2 , where the first " $ " appears, then php will interpret it as a variable, and the variable name is $v1;

 

      3 , we know that the value of $v1 is "abc",

 

      4 , then, the variable name after the first " $ " symbol is obtained as " abc "

 

      5 , that is: what echo tries to output is the variable $abc , which is naturally the number 10

 

      In fact, in theory, mutable variables can be nested more, such as: $$$def;

6. Predefined variables

   Predefined variables are also called super global variables. They are already defined by the system and can be used directly. Their data types are arrays.

   Commonly used are $_GET $_POST $_SERVER $_REQUEST $GLOBALS, $_COOKIE $_SESSION...  

   $_GET: <a href=”abc.php?uName=test1&uPwd=123” > Submit</a> //No spaces, key-value pairs are received

   $_POST: mostly used for form data submission, with higher security

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325526074&siteId=291194637