What does the previous & number mean when defining a function?
Title, please give examples of experts. Thank you
Best answer [url=http://www.111cn.cn/bbs/space.php?username=qxhy123] link tag Qxhy123[/url]
[url=http://www.111cn.cn/bbs/space.php?uid=66514] link marker [img]http://www.111cn.cn/server/avatar.php?uid=66514& Size=small[/img][/url] below I come to reveal the correct answer, this is the forum e snail Children's shoes in the post to see, accurate description of the function before adding a & effect, as well as the specific effect.
A reference to the function returns
First look at the code to copy PHP content to the Clipboard
PHP Code:
function &test ()
{
Static $b =0;//declaration of a statically 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
The following explanation:
In this way $a=test (); The result is not a function reference return, which is not the same as a normal function call. The reason: It's php's rule.
PHP rules through $a=&test (); The way to get is the reference to the function is returned
As for what is a reference return (the PHP manual says that reference return is used when you want to use a function to find out which variable the reference should be bound to.) I haven't read this bullshit.
In the example above, the explanation is
$a =test () call the function, just assign the value of the function to $ A, and no change to $ A will affect the $b in the function.
by $a=&test (), the function is to call 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
http://www.bkjia.com/PHPjc/632607.html www.bkjia.com true http://www.bkjia.com/PHPjc/632607.html techarticle define the function before adding a size=small[/img][/url] below I come to reveal the correct answer, this is the forum e snail Children's shoes in the post to see, accurate description of the function before adding a test () {Stati ...