Jump to content

[SOLVED] What does the & symbol do when put infront of another variable?


Demonic

Recommended Posts

It creates a reference.  You should stay away from these unless you know what you're doing :)

 

A simple example:

 

$a = 5;
$b = &$a;
$b = 2;
print "a now has value $a\n";

 

When you make $b a reference to $a, the variables become shared.  Changes to either one will affect both.  Only one copy of the actual data is stored.

 

PS In general it's a bad idea to use references to try to save memory.  PHP already has mechanisms that save memory in most common situations where variables are copied.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.