What do you mean by adding a number before defining a function? _php Tutorials

Source: Internet
Author: User
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 ...

  • 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.