What does & represent in php?

Discussion in 'OT Technology' started by k2737, Mar 23, 2006.

  1. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Example.

    <? Supportchannels(&$db); ?>
    I understand it is calling the supportchannels method and passing the variable $db....but what does the & represent/mean/do before the variable? :sadwavey:
     
  2. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
  3. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,517
    Likes Received:
    619
    It's giving the address of the variable to the function so that it operates on the actual location in memory instead of just the value.

    Example:

    $a = 5

    function test1($a)
    {
    $a++;
    }

    function test2(&$a)
    {
    $a++;
    }

    test1($a);
    echo $a;
    test2($a);
    echo $a;

    will print this:
    5
    6

    It's called passing by reference instead of passing by value.
     
  4. Joe_Cool

    Joe_Cool Never trust a woman or a government. Moderator

    Joined:
    Jun 30, 2003
    Messages:
    299,517
    Likes Received:
    619
    :uh: I guess if I had read the thread, I would have seen that you already got the answer. :o
     
  5. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    Yeah but for anyone who didn't want to click on the link you sumed it up for them. :)
     
  6. mobbarley

    mobbarley Active Member

    Joined:
    Mar 4, 2005
    Messages:
    9,256
    Likes Received:
    2
    Location:
    Sydney
    like me :p
     
  7. antiyou

    antiyou OT Supporter

    Joined:
    Jul 13, 2005
    Messages:
    25,295
    Likes Received:
    0
    Location:
    in ur base
  8. k2737

    k2737 Active Member

    Joined:
    Nov 29, 2004
    Messages:
    3,324
    Likes Received:
    0
    Location:
    Ft Lauderdale
    I deal with networking not developing. :fawk:
     

Share This Page