PHP:使用NOT Equal(!=)运算符的多个条件不起作用 [英] PHP: Multiple conditions with NOT Equal (!=) operator is not working
问题描述
希望你会没事的。
我正在下面的代码中,如果条件有多个not运算符(下面的示例),我想使用多个php,但是当我执行以下php代码时,它总是返回true(总是用括号括起来的意思是内容总是执行),即使没有条件为真。
我想问一下下面的代码是什么问题。是否在php条件中使用多个!=运算符有任何特定的语法或规则。而且我很惊讶地发现,如果我将!=运算符替换为==运算符来使用以下代码,那么它运行良好。
Hope u people will be fine. I’m working on a following code in which i want to use multiple php if conditions with multiple not operators (example is below), but when i execute following php code, it always returns true (mean content in always parenthesis always executed) even no condition is true. I want to ask what is the problem in following code. Is there any specific syntax or rule for using multiple != operator in php conditions. And i am amazed to see that if i use following code by replacing != operator with == operator it is working fine.
if( $ext!="exe" || $ext!="html" || $ext!="htm" || $ext!="js" || $ext!="iso" || $ext!="zip" || $ext!="rar" )
{ // ececk extension
echo $ext."extension";
}
else{
echo "not match";
}
等待您的答复。
推荐答案
更好的代码:
$allowed = array('jpeg','png');
if(in_array($ext,$allowed)){
echo "Correct";
}
else {
echo "Wrong";
}
这篇关于PHP:使用NOT Equal(!=)运算符的多个条件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!