note 73550 deleted from language.operators.increment by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:22:10 +0000 |
| Subject: | note 73550 deleted from language.operators.increment by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189853@lists.php.net to get a copy of this message | ||
Note Submitter: Are Pedersen
----
Something to think about:
$a=1;
$a += $a++ + ++$a;
echo $a;
will give you 7.
Why is this?
1. ++$a is first incremented. Now $a is 2.
$a += $a++ + 2
$a is 2
2. $a++ is added to 2 then $a is incremented
$a += 2 + 2
$a is 3
3. now the value of 2 + 2 is added to $a ($a is 3)
$a = $a + 2 + 2
Answer: 3 + 2 + 2 = 7