+ 1
If this kind of program how it gave right answer? ??
<?php $x = 10; $y = 10; if ($x >$y) { echo $x; } else { echo $y; } ?>
8 Answers
+ 7
Won't this return 10 no matter what 'cos both values are 10?
+ 5
The if part will fail but the else part will execute.
+ 3
but the program is about big value between two but here both values are same so it will execute ???
+ 2
OK thank you..
+ 2
In case of ( $x == $y ) then the condition of your 'if' statement ( $x > $y ) return false, so it echos the value of $y: all is right...
You've probably just been confused by the fact that if you put ( $x >= $y ), the equal case is explicit, than implicit else, but in this second case the script will echos the value of $x: for the Python interpreter, that's two distinct case, than for a human observer just of output, it seems strictly equivalent ;)
+ 1
It will execute and will output 10 of y.
0
Your 'if' statement is asking a simple question; Is 10 greater than 10?
$x is NOT greater than $y. So the 'if' statement returns false. in the 'else' statement you have specified; if the statement returns false echo $y, which it does.
0
the if (condition)
{action to do if the condition is true}
else
{action to do if the condition is false}
so for you $x==$y but not $x>$y .in this case the second action will happen.then the output will be "10"