View Single Post
  #5 (permalink)  
Old 09-29-2006, 10:36 PM
Thomas Thomas is offline
Newbie
 
Join Date: Sep 2006
Posts: 15
Credits: 0
Rep Power: 9
Thomas is on a distinguished road
Lightbulb

Pass by reference essentially sets a pointer to the original variable's memory location so that you can "pass" the variable on to the function without needing to create a duplicate of the variable. And when the function changes the variable it also changes outside the function since the function is changing the same memory location that the original variable also points too.

For example

PHP Code:
<?php
//pass variable $a by reference
function foo(&$var)
{
//add 1 to $var which essentially adds 1 to $a since $var points to $a's memory location
   
$var++;
}

$a=5;
foo($a);
// $a is 6 here
?>
This example was taken off the php.net site see more information here.
Reply With Quote

Sponsored Links