What will be the output of the PHP code snippet below?



==========================
$v = 1;
$m = 2;
$l = 3;

if( $l > $m > $v){
    echo "yes";
}else{
    echo "no";
}
=========================

Ans:

Since 3 > 2 > 1, one might be fooled into thinking the output would be “yes”.

In fact, though, the output will be “no”.

Here’s why:


First, $l > $m will be evaluated which yields a boolean value of 1 or true. Comparing that boolean value to the integer value 1 (i.e., bool(1) > $v) will result in NULL, so the output will be “no”.

No comments:

Post a Comment