Who can explain in detail the execution process of $ a10; $ B $ a -- + -- $ a; in PHP? When I read Gao luofeng's book "elaborate on PHP", I found {code ...} if the above logic is used, add {code ...} can anyone tell us the detailed execution process of this code? Who can explain in detail the execution process of $ a = 10; $ B = $ a -- + -- $ a; in PHP?
When I read Gao luofeng's book "elaborate on PHP", I found that
$ A = 10; $ B = $ a ++ $ a; // The Execution Process in the book is: $ a First Auto-increment 1 and then auto-increment 1, then assign $ becho $ a; // $ a = 12; echo $ B; // $ B = 22; $ B = $ a ----- $; // $ a first incrementing by 1, then incrementing by 1, and then assigned to $ becho $ a; // $ a = 10 echo $ B; // $ B = 2
If the above logic is used
$b = $a-- + --$a;echo $a; //$a = 8;echo $b; //$b = 18;
Can anyone tell us the detailed execution process of this code?
Reply content:
Who can explain in detail the execution process of $ a = 10; $ B = $ a -- + -- $ a; in PHP?
When I read Gao luofeng's book "elaborate on PHP", I found that
$ A = 10; $ B = $ a ++ $ a; // The Execution Process in the book is: $ a First Auto-increment 1 and then auto-increment 1, then assign $ becho $ a; // $ a = 12; echo $ B; // $ B = 22; $ B = $ a ----- $; // $ a first incrementing by 1, then incrementing by 1, and then assigned to $ becho $ a; // $ a = 10 echo $ B; // $ B = 2
If the above logic is used
$b = $a-- + --$a;echo $a; //$a = 8;echo $b; //$b = 18;
Can anyone tell us the detailed execution process of this code?
Khan, three sections of code are the same, so it is necessary to put so much? No matter$a++
Or++$a
You only need to understand that the code is read from left to right.
$a++
It means$a
And then add 1 to it, so$b = $a++;
The output result is$a=11;$b=10;
++$a
Is first$a
Perform auto-increment 1, and then$a
Value, so$b = ++$a;
The output result is$a = 11;$b=11;
If you can understand the above two paragraphs, it is not a problem to understand your section based on this idea. Let me talk about your last one:
$b = $a-- + --$a;
This can be split
$c = $a--;$d = --$a;$b = $c + $d;
According to the above explanation,$a--
The returned result is$a
Value, and then$a
Auto-minus 1.$a=9;$c=10;
.--$a
Here is$a
Subtract 1 and then return$a
Value, so at this time$a=8;$d=8;
. The final result is naturally$a=8;$b=18;
.