Code: Select all
<?php
$var1 = 1;
$var2 = 1;
?>
<?php
$var11 = $var1++ + $var1;
echo $var11;
echo "<br />";
$var22 = $var2 + $var2++;
echo $var22;
?>
<br />
<?php
$var3 = 1;
$var4 = 1;
?>
<?php
$var33 = $var3++;
echo $var33;
echo "<br />";
?>3
3
1
My question is why does this compile to 3?
Code: Select all
$var22 = $var2 + $var2++;When this compiles to 1, and all I am doing is adding another $var2 +?
Code: Select all
$var33 = $var3++;P.S. And more of a QQ, starting out with C, $var11 and $var22 should both compile to 2 because I am using a post-increment operator and should do the increment after all expressions. C does it after all expressions, whereas Java does it as the expression evaluates (from left to right). If the compiler was thinking I meant $var44 = $var4 + ++$var4, this should compile to 4, not 3. I understand this is not the languages fault but the problem with learning more than one language. And I have tried to search Google with no luck.