<select name="<?= $name; ?>" title="<?= $title; ?>">
    <option value=""></option>
    <?php $seen_key = false; ?>
    <?php foreach ($values as $value): ?>
        <option value="<?= htmlspecialchars($value); ?>"
                <?php if ($foreign !== false && $value == $foreign): ?>
                    selected="selected"
                    <?php $seen_key = true; ?>
                <?php endif; ?>>
            <?= htmlspecialchars($value); ?>
        </option>
    <?php endforeach; ?>
    <?php if ($foreign !== false && ! $seen_key): ?>
        <option value="<?= htmlspecialchars($foreign); ?>" selected="selected">
            <?= htmlspecialchars($foreign); ?>
        </option>
    <?php endif; ?>
</select>
