PHP learning notes-variables in PHP

Source: Internet
Author: User

Variable in PHP (for more information, see the PHP manual ):

To put it bluntly, the variable in PHP parses the value of a variable into a variable name and reads the value of that variable name. Instance:

<? PHP  $ = "China "; //  Variable      $ B = ""; //  Variable B      $ China = "I'm Chinese! "; //  Variable China      $ F = "B "; //  Variable F         Echo   $ . "<Br/> "; //  Output China      Echo $ $ . "<Br/> "; //  Output I'm Chinese -- to resolve a variable, add a $ symbol to the front.      $ = "F "; //  Change the name to which the variable points (here is the application of the variable)      Echo $ $ . "<Br/> "; // Output B after pointing to the variable F above      $ = "B "; //  Same as above      Echo $ $ . "<Br/> "; //  Output          Echo   $ B . "<Br/> "; //  Output      Echo $ $ B . "<Br/> "; // Output B      Echo $ $ B . "<Br/> "; //  Output          Echo   $ F . "<Br/> "; //  Output B      Echo $ $ F . "<Br/> "; //  Output      Echo $ $ F . "<Br/> "; //  Output B      Echo $ $ F . "<Br/> "; //  Output  $  $ = "China "; //  The last variable changed to the value of $ B, which is called $ A = $ B.      Echo   $ B . "<Br/> "; //  Output China     Echo $ $ B ; //  Output I'm Chinese ?>

Note: Variable variables cannot be applied to $ this and super global variables (the scope of PHP variables and other advanced variables ).Programming LanguageDifferent. ViewCode)

<? PHP  $ Name = 'Man' ; $  $ Name = 'Abc '; //  If there is no man variable in advance. Create a new man variable. Then assign the ABC value. $ $ Name = 'Def';  Echo   $ Man . "<Br/> "; //  Output ABC      Echo   $ ABC ; //  Output def          Echo "<Br/> <HR/>" ;  Function  Show (){  Global   $ Name ;//  Global is not set as a global variable. But references          Echo   $ Name . "<Br/> "; //  Output man  }  Function  Showtwo (){  //  Global $ name; // echo $ name. "<br/> ";          Echo   $ Globals ['Name']; //  Super global variable array } Show (); showtwo (); ?>

 

Variable Functions:

<? PHP  Function  B (){  Echo "This is B" ;}  Function C ( $ Name = "China ") //  Set Default Value  {  Echo "This is $ Name " ;}  $ = 'B' ;  $ (); //  Function for finding the value           $ = 'C' ;  $  ();
?>

 

 

 

A typical application of variable variables:

<! Doctype html Public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml">  PHP  Foreach ( $ _ Post  As   $ Key => $ Value  ){  //  Print_r ($ _ post ); $ $ Key = $ Value  ;}  //  Extract ($ _ post); // import the variable from the array to the current symbol table-find the PHP manual by yourself          Echo   $ Name . "<Br/>" ; Echo   $ Pwd . "<Br/>" ;  Echo   $ Tag . "<Br/>" ; ?> </Body> 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.