开发者

Way to store variable value is different than the way to store variable address(location)

开发者 https://www.devze.com 2022-12-22 06:18 出处:网络
Is it true that the syntax for (assign of variable value) is different than the syntax for 开发者_StackOverflow社区(assign of address) in PHP.

Is it true that the syntax for (assign of variable value) is different than the syntax for 开发者_StackOverflow社区(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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消