I have this following code:-
$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; }
If $ad['country'] has united states, united kingdom or canada then it should pass or else if there are different values other than the above it should go in else rest.
Example:- Ad 1 has: ( united states;united kingdom ) > Then it should pass as $adsptc4 Ad 2 has: ( united states;italy ) > Then it should fail.
Let me know if you did not understand something.
<?
$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";
}
?>
Works good, Let me know if there are any drawbacks out of it.