in reply to $i=$i++
I ran the following code:
And got the following output:$i = $i++; print "Test 1: $i\n"; $i = 0; $i = 0 + $i++; $i = ++$i + $i++; print "Test 2: $i\n"; $i = 0; $i = ++$i + $i++; print "Test 3: $i\n"; $i = 0; $i = $i++ + ++$i; print "Test 4: $i\n";
Remebering what Ovid said about pre vs. post increment, when you examine this output you may realize that by the time the print statements in Test2, Test3, and Test4 have been executed, $i has actually been incremented one last time by the post increment operator.Test 1: 0 Test 2: 3 Test 3: 3 Test 4: 2
So if you thought your output was weird maybe this has something to do with it.
UPDATE: I was going through my posts and found this one. The final incrementation I mention I believe is ultimately irrelevant since the expression's return value i assigned to $i thereby over-writing the value $i has after the ++ operator.
|
|---|