<select name=""> <option value="0"></option> <?php foreach ($departments as $department) { if ($selected !== 0 && $selected === $department['id']) { echo '<option value="' . $department['id'] . '" selected="selected">' . $department['title'] . '</option>'; continue; } echo '<option value="' . $department['id'] . '">' . $department['title'] . '</option>'; } ?> </select>
$departments
is a classifier, i.e. the list itself is stored in a database, but it can also be stored in an array ...
$departments = array( array('id' => '1', 'title' => 'Ленинский'), array('id' => '2', 'title' => 'Парк культуры') ... );
$selected
is the saved value from the same list.