I am trying to set selected
on an <option>
based on an array, and I'm close, but not quite getting there...
$departments = array("Finance", "IT", "Retail",);
foreach($departments as $list){
echo '<option';
if($found['dept'] == '$list'){ // if I set this manually it works, but not now
echo ' selected';
}
echo ' >' . $list . ' </option>'; // this works fine to show me the list
}
If I set $found[dept]
manually like below, echoing 'selected' works great, but I don't want to write a version of this line for every option.
if($found['dept'] == 'Finance'){ echo 'selected';} > ' .$list . '</option>