• 0

Some php


Question

what does the & do when placed before a variable? like &$variable i've seen it used only in a function eg. funtion test(&$var) { some stuff }

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

It refers to the address of the variable in memory. This means that the function won't be passed the value of $var, it will be passed the position of $var in memory. This enables the function to change that variable if and when it's needed and when the function returns, the variable will keep it's new value.

Practical uses in PHP are that you can have a function return practically unlimited values by passing their address through the function paramaters. In C/C++ these are called pointers and allow all sorts of funky things, but I don't know if PHP covers thinks like pointers to functions and linked lists.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.