gpt4 book ai didi

php - 奇怪的php if语句问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:51:17 24 4
gpt4 key购买 nike

if($country == 224 || $country == 223 || $country == 39 && $zip == '' ){
$_SESSION['sess_msg'] = "Please enter a Valid zipcode";
header("location: $SITE_PATH?p=account.profile.name");
exit;
}
variable   value--------   -----$country     224$zip       11111

我知道 $zip 不是空的,但代码执行时就好像它是空的一样。我什至在调试语句中将其打印到浏览器以验证它是否具有值。

是什么导致我的程序表现得好像 $zip 没有值?

最佳答案

&& 运算符具有更高的 precedence|| 运算符。所以你的表达等于:

$country == 224 || $country == 223 || ($country == 39 && $zip == '')

解决方法:

($country == 224 || $country == 223 || $country == 39) && $zip == ''

关于php - 奇怪的php if语句问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1179686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com