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
?>

Comments

Popular posts from this blog

Timus Problem 1086. Cryptography Accepted Solution in C

Timus 1209. 1, 10, 100, 1000... accepted solution in C

Timus 1083. Factorials!!! Accepted Solution in C