Page 1 of 1

Function and the operator &

Posted: Mon Feb 16, 2004 1:27 pm
by Draco_03
When you crate a function, i know it takes a & in case like this one :

Code: Select all

function addFive( &$num ) {
	$num += 5;
}
$orignum = 10;
addFive( $orignum );
print( $orignum );
?>
but why..i just need someone to explain the use of & in a function befor a variable name..

thx :)

Posted: Mon Feb 16, 2004 3:12 pm
by Sevengraff
It means you are passing the data by refrence, and not making a copy of it. in your example, print( $orignum ); would output 15. This allows the function access to data outside of it's normal scope

Posted: Mon Feb 16, 2004 5:01 pm
by DuFF

Posted: Tue Feb 17, 2004 8:41 am
by Draco_03
thx guys :)