Sir Rugmuncher Posted April 26, 2003 Share Posted April 26, 2003 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 More sharing options...
0 Quboid Posted April 26, 2003 Share Posted April 26, 2003 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 More sharing options...
0 Tim Dorr Veteran Posted April 26, 2003 Veteran Share Posted April 26, 2003 Actually, it's a reference to a symbol table entry. References have some big differences from C pointers, so it's important to note that you won't get the same results always if you think of them in the same way. For you C people out there: & != * Suggested reading: http://www.php.net/manual/en/language.references.php Link to comment Share on other sites More sharing options...
Question
Sir Rugmuncher
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