A reference-related question. could you please help me! Thanks

Source: Internet
Author: User
For a reference question, please help me! Thank you & lt ;? Php & nbsp; function & nbsp; demo (& amp; $ a, & nbsp; & amp; $ B) & nbsp ;{& nbsp; $ a & nbsp; & amp; & nbsp; $ B; & nbsp ;}& nbsp; $ a & nbsp; 1; & nbsp; $ B & nbsp; 2; & nbsp; demo ($ a, for a reference question, please help me! Thank you.

Function demo (& $ a, & $ B) {$ a = & $ B ;}
$ A = 1;
$ B = 2;
Demo ($ a, $ B );
$ B = 3;
Print $;
?>
Detailed source reference: http://www.jb51.net/article/22508.htm

What I saw when I read a reference article,
The result is 2,
I think the result is 3,
The result after running is 1.
I am a beginner in php. I don't quite understand its reference parameter passing ,,,,,,
------ Solution --------------------
For ease of description, the parameter name is changed
function demo(&$x, &$y) {
$x =& $y;
}
$a = 1;
$b = 2;
demo($a, $b);
print $a;

& $ X is another form of global $
Therefore
$ X = & $ y;
Yes
Global $;
$ A = & $ y;
Hope you can understand this.

The manual includes: If a global variable is assigned to a reference within a function, the reference is only visible within the function.

I won't talk about anything anymore.

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.