-1

Possible Duplicates:
Reference - What does this symbol mean in PHP?
what do “=&” / “&=” operators in php mean?

Sorry guys I feel like I'm asking too simple of a question but what is =& in PHP? I tried to use this group function with ACL in Cakephp...

Community
  • 1
  • 1
Passionate Engineer
  • 8,614
  • 22
  • 84
  • 151

2 Answers2

4

You use =& when you want to assign a variable by reference. For more information see http://php.net/manual/en/language.references.php.

Example:

$a = array(1, 2, 3);
// $b is a reference to $a.
// If you change $a or $b, the value for both $a and $b will be changed.
$b =& $a;

$c = array(1, 2, 3);
// $d is a copy of $c.
// If you change $d, $c remains unchanged.
$d = $c;
Francois Deschenes
  • 23,823
  • 3
  • 61
  • 58
  • So this would be similar to $$ variable variable? – Passionate Engineer Jul 14 '11 at 18:11
  • @Jae Choi - No. The only time you'd want to use `$$` is if you want to dynamically refer to a variable. For instance: `$variable = 'test';` you could do `$$variable` and PHP would interpret it at `$test` (it replaces the `$variable` with it's value) but I wouldn't recommend coding that way. It'll make your code extremely difficult to read. – Francois Deschenes Jul 14 '11 at 18:13
0
$b = 3;
$a =& $b;
$b = 5; //$a is 5 now
$a = 7; //$b is 7 now
RiaD
  • 42,649
  • 10
  • 67
  • 110