Hi,

I've seen a function that starts like this:

function name($section, &$data)

Now I'm wondering why the '&' symbol in front of the variable? Anyone?

    The & symbol means reference... It is derived from C++, where you use things to point to things:

    You got a variable named $cat, and $cat = 3. And you can say $bob = $cat, that would define $bob as 3 but it would have to first find out what $cat is. However if you type $bob =& $cat, it is a reference, that $bob is equal to 3.

    I don't know how else to describe it, but it basically is important to speed up your applications, so it says "its the same value as $cat" rather than "its the same value as $cat which is 3" so it speeds things up.

      Oh OK I get it!!! 🙂

      Thanks alot!

        Except that they do not speed code up, nor is that what they're for. Everything execute describes with talk about $bob and $cat is done by PHP anyway and has done so for years. So changing $bob = $cat to $bob &= $cat won't make any difference to speed.

        References are a way for several variables to be aliases for the value, so that changing the value using one alias changes it for the others as well.
        See the manual's chapter on [man]references[/man] for details.

          Write a Reply...