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>