If you go through for you will find all the expressions are wrong –
For for($x++ ; $x==2 ; $x=2)
The first
$x++
0
. – Incrementing an undefined variable sets it to 1, because it converts null to 0 when it’s used in an arithmetic context..The second
$x==2
will returnfalse
and the iteration will not be executed.The third
$x=2
will be executed at the end of each iteration.
So, the iteration will never be executed as $x==2
is always false
.
And the output will be After the loop
9
solved what will be the output of following code in PHP? [closed]