+ 1

If this kind of program how it gave right answer? ??

<?php $x = 10; $y = 10; if ($x >$y) { echo $x; } else { echo $y; } ?>

31st Jan 2017, 8:23 AM
The YK
The YK - avatar
8 Respuestas
+ 7
Won't this return 10 no matter what 'cos both values are 10?
31st Jan 2017, 8:28 AM
Jafca
Jafca - avatar
+ 5
The if part will fail but the else part will execute.
31st Jan 2017, 8:31 AM
Jafca
Jafca - avatar
+ 3
but the program is about big value between two but here both values are same so it will execute ???
31st Jan 2017, 8:30 AM
The YK
The YK - avatar
+ 2
OK thank you..
31st Jan 2017, 8:33 AM
The YK
The YK - avatar
+ 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 ;)
31st Jan 2017, 11:50 AM
visph
visph - avatar
+ 1
It will execute and will output 10 of y.
31st Jan 2017, 4:02 PM
Rowela P. Alzona
Rowela P. Alzona - avatar
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.
3rd Feb 2017, 5:30 AM
Jacob Ochoa
Jacob Ochoa - avatar
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"
21st Feb 2017, 11:55 AM
Fabien Godcoder
Fabien Godcoder - avatar