1

Possible Duplicate:
Reference - What does this symbol mean in PHP?

Can anyone explain this experssion

&variablename in PHP.

I have seen this around at many places but i am not able to figure out what does this statement do.

Thanks in advance

J

Community
  • 1
  • 1
Akhilesh Sharma
  • 1,580
  • 1
  • 17
  • 29

2 Answers2

1

PHP reference. References in PHP are a means to access the same variable content by different names. There are three operations performed using references: assigning by reference, passing by reference, and returning by reference.

PHP reference

for example:

$example1 =  'something';
$example2 =& $example1;
echo("example 1: $example1 | example 2: $example2\n"); //example 1: something | example 2: something
$example1 = 'nothing'; //change example 1 to nothing
echo("example 1: $example1 | example 2: $example2"); //example 1: nothing | example 2: nothing
KJYe.Name
  • 16,969
  • 5
  • 48
  • 63
0

You can pass variable to function by reference, so that function could modify its arguments. The syntax is as follows:

<?php
function foo(&$var)
{
   $var++;
}

$a=5;
foo($a);
// $a is 6 here
?>

taken from http://www.phpbuilder.com/manual/language.references.pass.php

keithics
  • 8,576
  • 2
  • 48
  • 35