note 73550 added to language.operators.increment
| From: | ArePedersen at osu1 dot php dot net | Date: | Wed, 28 Feb 2007 23:08:36 +0000 |
| Subject: | note 73550 added to language.operators.increment | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123969@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 85.196.72.154
----
Manual Page -- http://www.php.net/manual/en/language.operators.increment.php
Edit -- https://master.php.net/note/edit/73550
Del: integrated -- https://master.php.net/note/delete/73550/integrated
Del: useless -- https://master.php.net/note/delete/73550/useless
Del: bad code -- https://master.php.net/note/delete/73550/bad+code
Del: spam -- https://master.php.net/note/delete/73550/spam
Del: non-english -- https://master.php.net/note/delete/73550/non-english
Del: in docs -- https://master.php.net/note/delete/73550/in+docs
Del: other reasons-- https://master.php.net/note/delete/73550
Reject -- https://master.php.net/note/reject/73550
Search -- https://master.php.net/manage/user-notes.php