Possible Duplicate:
'AND' vs '&&' as operator
Sorry for very basic question but I started learning PHP just a week ago & couldn’t find an answer to this question on google/stackoverflow.
I went through below program:
$one = true;
$two = null;
$a = isset($one) && isset($two);
$b = isset($one) and isset($two);
echo $a.'<br>';
echo $b;
Its output is:
false
true
I read &&/and are same. How is the result different for both of them? Can someone tell the real reason please?
The reason is operator precedence. Among three operators you used
&&,and&=, precedence order is&&=andSo
$ain your program calculated as expected but for$b, statement$b = isset($one)was calculated first, giving unexpected result. It can be fixed as follow.