Secret of post increment in PHP
<?php
$x = 1;
$x = ($x++) + 1; // This statement equals to $x = 1 + 1, here $x++ statement puts the value of $x in its place and then execute itself. After that, $x = ($x++) + 1 which means $x = 1 + 1 is executed.
echo $x; // outputs 2
?>
$x = 1;
$x = ($x++) + 1; // This statement equals to $x = 1 + 1, here $x++ statement puts the value of $x in its place and then execute itself. After that, $x = ($x++) + 1 which means $x = 1 + 1 is executed.
echo $x; // outputs 2
?>
Comments
Post a Comment