Monday, April 16, 2012

Confusion over the value of a variable after running a PHP program

I'm studying for my finals and I came across this question:




consider this following PHP code, write the output after executing it



<?php
$a=3;
$b=$a++;
IF($a>$b)
{
echo "a>$b";
}
else if ($a == $b)
{
echo "a=$b";
}
else
{
echo "a < $b";
}
?>



When I output it in my text editor I get a < 3, but I don't understand why though?



I thought a is assigned to 3 and also b is assigned to a++ 3 and 3==3 so should a==3 be printed out?





No comments:

Post a Comment