我正在尝试使用以下代码检查用户是否来自荷兰或比利时以外的地区':
$countrycode = 'NL';
if ($countrycode !== 'NL' || $countrycode !== 'BE') {
echo 'you are not from NL or BE';
} else {
echo 'you are from: ' . $countrycode;
}
我无法弄清楚为什么它会在第一次出现时回响。
PS:我知道我可以通过使用===
来改变它,但我想知道为什么或我做错了什么。
谢谢
答案 0 :(得分:8)
那应该是AND而不是OR。
chdir
你的第一行应该是:
$countrycode = 'NL';
if ($countrycode !== 'NL' || $countrycode !== 'BE') { // Since 'NL' !== 'BE' this is true
echo 'not from NL or BE';
} else {
echo 'you are from: ' . $countrycode;
}
答案 1 :(得分:0)
尝试方法strcmp():http://php.net/manual/de/function.strcmp.php 请记住,它返回一个整数而不是布尔值。字符串的相等性用0表示为返回值。 此比较也区分大小写。