PHP mutable variables

Source: Internet
Author: User

variable variable: That means a variable Variable gets a the value of the normal variable as this Variable name of variable variable . For example:


<?Php
Header"Content-type:text/html;charset=utf-8");
$uername=' There's a girl in the village ';
$name=' Xiaofang ';
$xiaofang=' The girl of Osaka Castle ';

//$$name =$xiaofangEcho$ $name;

//Use of variable variables
$banzhuren=' Xucaihui ';
$xucaihui=' man ';
$man=' lvyou ';
$lvyou=' Taiguo ';
$taiguo=' It's a woman '.;

Echo$ $ $banzhuren;

Output: The girl from Osaka Castle is a woman.

A reference to a variable is assigned a value:

The reference operator & can be used in associative assignments, just like an alias, so that the variable points to the same address in memory.

(Headphones example: Only one song, left and right can be heard, one of them broken, another heard the same song

MP3 in the original there are 2 songs, after the variable reference assignment, will be one of the deleted, the appearance of two buttons, one is a small Apple song, the other is a small orange song, the small orange deleted, two buttons can only choose a song, the output is the same)

<?Php
$user=' Canglaoshi ';
$name= ' Wulaoshi ';


//Causes the value of the $name to point to $user, and discards the value of $name
$name=&$user;

Echo$name;
Echo' <br/> ';
Echo$user;

//Determine if the result is the same, the result is a 10-byte string
if(Empty($name)) {
Echo' Kong ';
}Else{
Echo' Feikong ';
};
Echo' <br/> ';
Var_dump ($user);
Echo' <br/> ';
Var_dump ($name);
Echo' <br/> ';
//Destroy variable $user, $name output is still canglaoshi, enough to prove that only one value is left in memory
unset($user);
Echo' <br/> ';

Echo$name;
Echo$user;

Output Result:
Canglaoshi
Canglaoshifeikong
StringTen)"Canglaoshi"
StringTen)"Canglaoshi"

Canglaoshi
Notice:Undefined variable:User in D:\xampp\htdocs\ the\exercise\ the-7- -PHP kongzhiyuju\01yinyon. PHP on line in


This article is from the PHP Learning notes blog, so be sure to keep this source http://phpst.blog.51cto.com/6922579/1557171

PHP mutable variables

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.