No notice or error inside foreach is expected when $DORMS
is empty. Code inside foreach
does not get executed when $DORMS
is empty. When you have some value in $DORMS
you can see that notice using chrome dev tools or firebug.
EDIT
Notice has nothing to do with foreach
loop. You do not see the notice because it is generated inside a <select>
element in html. Browser is not showing any normal text that is inside <select>
. If your foreach
loop was inside a <p>
html element you could see that message as the browser would output that.
<p>
<?php foreach ($DORMS as $dorm){
if ($_POST['dorm'] == $dorm){
echo "<option selected value=\"$dorm\">$dorm</option>";
} else {
echo "<option value=\"$dorm\">$dorm</option>";
}
}
?>
</p>