“和"之间是否有任何区别?和“&&" PHP中的运算符? [英] Is there any difference between "and" and "&&" operators in PHP?
本文介绍了“和"之间是否有任何区别?和“&&" PHP中的运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,并且认为不需要和,即应使用&&
,因为没有什么可分配左部分的?
I have the following code and don't think and is needed, i.e. &&
should be used, as there is nothing to assign the left part to?
if($_REQUEST['foo'] != 'abc' and $_REQUEST['bar'] == 'def')
{
echo "all your base";
}
应该是:
if($_REQUEST['foo'] != 'abc' && $_REQUEST['bar'] == 'def')
{
echo "all your base";
}
推荐答案
In your case, &&
and and
do the same thing, but take a look at the operator precedence. You can see that &&
and and
are not on the same level, so mixing that could give you unexpected results in some cases - I recommend always using &&
, but that's your choice.
这篇关于“和"之间是否有任何区别?和“&&" PHP中的运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文