References to PHP variables and references to functions

Source: Internet
Author: User

A reference to the PHP variable and a reference to the function are put back

A reference to a variable
$a = "ABC";
$b =& $a;
echo $a;//output here: ABC
echo $b;//output here: ABC
$b = "EFG";
echo $a;//The value of $ A here becomes EFG so the output EFG
echo $b;//Output EFG here

A reference to the function returns
function &test ()
{
Static $b =0;//declares a statically engineered variable
$b = $b +1;
Echo $b;
return $b;
}

$a =test ();//This statement outputs a value of $b of 1
$a = 5;
$a =test ();//This statement outputs a value of $b of 2

$a =&test ();//This statement outputs a value of $b of 3
$a = 5;
$a =test ();//This statement outputs a value of $b of 6
$a =&test () calls the function, and his role is to point the memory address of the $b variable in the return $b to the same place as the memory address of the $ A variable
That produces the equivalent effect ($a =& $b;) So changing the value of $ A also changes the value of the $b so that it executes the
$a =&test ();
$a = 5;
Later, the value of the $b becomes 5

References to PHP variables and references to functions

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.