我有以下代码: -
$unitedstatess = stristr($ad['country'], 'united states');
$unitedkingdom = stristr($ad['country'], 'united kingdom');
$canada = stristr($ad['country'], 'canada');
if (($unitedstatess != FALSE) OR ($unitedkingdom != FALSE) OR ($canada != FALSE)) { $adsptc4.=$tempcode; }
如果 $ad['country'] 有美国、英国或加拿大,那么它应该通过,否则如果有除上述之外的不同值,它应该进入 else 休息。
示例:- 广告 1 有:(美国;英国)> 那么它应该通过 $adsptc4 广告 2 有:(美国;意大利)> 那么它应该失败。
如果您有不明白的地方,请告诉我。
<?
$ad['country'] = "United States;canada";
$allowed = array(
'united states' => true,
'united kingdom' => true,
'canada' => true
);
$countries = strtolower($ad['country']);
$countries = explode(";", $countries);
$found = false;
foreach($countries as $c) {
if(isset($allowed[$c]) == FALSE) {
$found = true;
break;
}
}
if($found != true) {
echo "true";
}
else {
echo "false";
}
?>
效果很好,如果有任何缺点,请告诉我。