我试图通过使用以下"代码"检查用户是来自荷兰或比利时以外的地方:
$countrycode = 'NL';
if ($countrycode !== 'NL' || $countrycode !== 'BE') {
echo 'you are not from NL or BE';
} else {
echo 'you are from: ' . $countrycode;
}
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚为什么它会在第一次出现时回响.
PS:我知道我可以通过改用===
来改变它,但我想知道为什么或我做错了什么.
谢谢
这应该是AND而不是OR.
$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;
}
Run Code Online (Sandbox Code Playgroud)
你的第一行应该是:
if ($countrycode !== 'NL' && $countrycode !== 'BE') {
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
73 次 |
最近记录: |