tags:

views:

16

answers:

1

Hello,

Is it true that the syntax for (assign of variable value) is different than the syntax for (assign of address) in PHP.

Like: If we want to store variable value to another variable then we can do it like this:

$b=2;
$a=$b;
print $a;
print $b;
// output is 22

But if we want to store variable address to another variable then we can do it like this:

$b=2;
$a=&$b; // note the & operator
$a=3;
print $a;
print $b;
// output is 33

Note that first time $b contain '2' then after $a=&$b; $b will contain '3' , now the point to think that if we want to store variable value then we will use $a=$b; & if we want to store variable location address then we will use $a=&$b;

My conclusion:

The way of value storing is like:

$store_destination = $store_source;   // ie: value save from right to left.

but the way of address storing is like:

$store_source = $store_destination;   // ie: address save from left to right.

Am i right?

Thanks.

+2  A: 

In PHP we don't talk about address and pointers explicitly, instead we talk about a concept called references.

In case 2, you are making $b a reference to $a as a result of which they both refer to the same content. Any change made to either will also change the other.

codaddict
Muhammad Sajid