This post was last edited by Lscxp on 2013-08-29 18:18:23
Reference PHP
$a = 2; $b = & $a; Echo (+ + $a) + ($a + +);
This is 7.
$a = 2;echo (+ + $a) + ($a + +);
The answer is 6.
But that $b is useless from beginning to end, why is the answer different after adding a line?
Reply to discussion (solution)
Look at this.
http://bbs.csdn.net/topics/390571704
One day two people ask the same question
$b = & $a; The
should turn variable A into a reference type.
$a = 2;
Echo (+ + $a) + ($a + +);
procedure is
to run a $ A self-increment, and then return the result of the increment, that is, 3
($a + +)
$a + + result is 3, and then execute a $ A self-increment, but the result of the expression has returned is 3
so the output is 3+3, A is 4
and
$a = 2;
$b = & $a;
Echo (+ + $a) + ($a + +);
is different, (+ + $a) is not affected,
($a + +) is not the same as before, should be the return value of the $a,
should now be returned to the address of $ A (or, of course, to get the actual value through the address)
returns a $ A address, a $ A increment, a becomes 4, Instead of just getting a $ A address,
now addresses the fetch value, so getting to the 4
result is 3+4
$b = & $a;
The variable a should be converted to a reference type.
$a = 2;
Echo (+ + $a) + ($a + +);
Process is
Run a $ A self-increment and then return the result after the increment is 3
($a + +)
The result of $a + + is 3, and then a $ A increment is executed, but the result of the expression has returned is 3
So the output is 3+3, A is 4.
and
$a = 2;
$b = & $a;
Echo (+ + $a) + ($a + +);
(+ + $a) will not be affected,
($a + +) is not the same as before, it should be the return $a value,
Now it's time to return the address that points to $ A (or get the actual value by address, of course)
When a $ A address is returned, a $ A increment is executed, a becomes 4, and the previous only gets the address of $ A,
Now the address gets the value, so it gets 4.
The result is 3+4.
$a = 2;
$b = & $a;
Echo ($a + +) + (+ + $a); The result is 6.
How do we explain this?
& $a means link so 3+3=6