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
I know that $zip
isn't empty, but the code executes as if it is. I even print it out to the browser in a debugging statement to verify that it has a value.
What is causing my program to act as if $zip
does not have a value?
The &&
operator has a higher precedence than the ||
operator. So your expression is equal to:
$country == 224 || $country == 223 || ($country == 39 && $zip == '')
The solution:
($country == 224 || $country == 223 || $country == 39) && $zip == ''
Have you tried using parentheses to give order to your operations?
($country == 22 || $country == 223 || $country == 39) && ($zip == '')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With