I’m trying to compare a defined code against a set of blocked country codes. In the following example the country code is getting caught in my if block:
$country_code = 'US';
if ($country_code == ("NG" || "RO" || "VN" || "GH" || "SN" || "TN" || "IN" || "ID" || "KE" || "CN" || "CI" || "ZA" || "DZ" || "RU")) {
print "COUNTRY CODE: $country_code<br>";
}
I see this for my results”
COUNTRY CODE: US
I wouldn’t expect ‘US’ to get caught…what am I missing?
What you are doing is
OR-ing strings together. Since non-empty strings converted to boolean values are true, this evaluates to the following:Since
$country_codeis also a non-empty string, that also evaluates totrue:Thus, you get
TRUE.To solve your problem, you need to do what Pekka suggests:
See also: