I have this foreach, which matches a postal code $searchvalue to an array of districts. The if statement does its job and executes succesfully, if there is no else.
However, when I uncomment the else, then the else is always executed.
Why is this the case?
foreach ($districts['district'] as $district) {
if (in_array($searchvalue, $district['postalcodes'])) { //Search for known Postal Code
$emails[] = $district['email'];
//Assign new mail address
$notification['to'] = implode("",$emails);
//Continue sending email
return $notification; //this succeeds without the else below. When the Else is uncommented, this is not executed.
}
else {
//No known postal code found, fallback
echo "no valid postal code found, fallback";
$notification['to'] = $defaultaddress;
return $notification;
}
}
Aucun commentaire:
Enregistrer un commentaire