I'm trying to set a cookie depending on if the users country code is available in an array.
$Countries = array(
"SE" => "swe",
"DEU" => "ger",
"NLD" => "dut",
"HRV" => "cro",
"FRA" => "fr",
"HUN" => "hun",
);
foreach($Countries as $Key => $Value) {
if($this->Country($_SERVER["REMOTE_ADDR"]) == $Key) {
setcookie('LanguageCookie', $Value, time()+(10 * 365 * 24 * 60 * 60));
setcookie('LanguageIsNative', true, time()+(10 * 365 * 24 * 60 * 60), '/');
break;
} else {
setcookie('LanguageCookie', $Configuration["Config"]["DefaultLanguage"], time()+(10 * 365 * 24 * 60 * 60));
break;
}
}
Now, If my country code is "SE" it will work and it will set the cookie LanguageCookie to swe. But if my country code is anything below "SE" in the array, for example "HRV", it will fail and run the else block (keep in mind that if the country code doesnt exist in the array, it should run the else block).
I break the loop because other it'd just go on and in the end just run the else block, even if the country code exists.
How can this be fixed?