PHP- variable grammar and basic operation

variable

  Popular, the variable is a variable amount in PHP used to point to a scalar data type, you can also point to a complex data types, variables, looking for data memory address, then we can replace variables point to a memory address, to variable again assignment, of course, also possible to remove the memory address corresponding to the variable data by accessing the variable.

Four basic operational variable

  Assignment: $ a = 10;

  Value: $ b = $ a - 5;

  Judge: isset ($ c) $ c variable to determine whether there is

  Delete: unset ($ a) remove the variable

? < PHP 
     $ aa = 10; // declare a variable $ aa, and assign 10 
    $ bb = $ aa - 5; // declare a variable $ bb, then by accessing the variable $ aa operations do get value 
    echo "<br>" ;
     echo  $ BB ; // this case is $ BB. 5 
    echo "<br>" ;
     IF ( isset ( $ CC )) {
        echo "to true" ; 
    } the else {
        echo "to false"; // undefined $ CC variable, printing to false 
    }
     // determines whether there is a $ AA 
    iF ( isset (AA $ )) {
        echo "to true"; // the presence of variable $ AA, to print to true; 
    } the else {
        echo "to false" ; 
    } 

    the unset ( $ AA ); // Delete AA variable $ 

    IF ( isset ( $ AA )) {
        echo "to true" ; 
    } the else {
        echo "false"; // undefined variable $ aa, so print false 
    }
   >?

The value of the variable passed and passed by reference

// variable transmission and reference transmission value 
    
    // value passed 
        $ m = 10 ;
         $ n- = $ m ;
         echo  $ n- ;
         $ m =. 9 ;
         echo "<br>" ;
         echo  $ n- ;
     // the value of the variable transmission to pass only a value, but does not pass the memory location 

    // reference transfer 
        $ m = 10 ;
         $ n- = & $ m ;
         echo "<br>" ;
         echo  $ n- ;
         $ m =. 9 ;
         echo "<br>" ;
        echo  $ n- ;
     // variables passed by reference, m passed directly to a memory location n, so in this case n, m is a location, a line grasshopper.

PHP predefined variables

  Many PHP predefined variables are "super-global", which means they are available in all scopes of a script. These are superglobals

    $GLOBALS
    $_SERVER
    $_GET
    $_POST
    $_FILES
    $_COOKIE
    $_SESSION
    $_REQUEST
    $_ENV

  <?php 

    $uname = "";
    $upwd = "";
    $flag = true;
    if (isset($_REQUEST["username"])) {
        $uname = $_REQUEST["username"];
        $upwd = $_REQUEST["userpwd"];
        if ($uname == "xiaobai"&&$upwd=="120165") {
            echo "恭喜您,登录成功";
            $flag = false;
        }else{
             echo "抱歉,登录失败";
        }
    }
     ?>

     <?php if ($flag): ?>
         <form action="" method="post">
            账户名:<input type="text" name="username">&nbsp;码:<input type="text" name="userpwd">
            <input type="submit" value="提交">
        </form>
     <?php endif ?>

Guess you like

Origin www.cnblogs.com/bai-boy/p/12159548.html