PHP if/else错误

Jas*_*vis 0 php demorgans-law

在下面的PHP中,如果我使用==比较一个变量,它就像我期望的那样工作,如果我使用!=然后我的代码中断,有人可以解释或帮助吗?

$_GET['p'] = 'home';

// DOES NOT work, it will always return "show JS" regardless to what string I have
if ($_GET['p'] != 'home' || $_GET['p'] != 'create.account'){
    echo 'show JS';
}else{
    echo 'do not show JS';  
}

// Works as I would expect it to
if ($_GET['p'] == 'home' || $_GET['p'] == 'create.account'){
    echo 'do not show JS';
}else{
    echo 'show JS'; 
}
Run Code Online (Sandbox Code Playgroud)

ere*_*non 9

$ _GET ['p']不能同时是两个不同的东西.你说第一个表达式; p不在家或不是create.account.它总是如此.您应该使用&&而不是||

  • 简单地误用DeMorgan定律(http://en.wikipedia.org/wiki/Demorgan%27s_law) (3认同)