Making a preselected drop-down selection box in HTML I'm a PHP newbie and I have a question. Is there a better way to do this? A nice solution?

$list = isset($_GET['list']) ? htmlspecialchars($_GET['list']) : "experience";

&lt;select name="type" id="type"&gt;
&lt;option value="experience"&gt;Experience&lt;/option&gt;
&lt;option value="magic"&lt;?=$list == "magic" ? 'selected' : '';?&gt;&gt;Magic Points&lt;/option&gt;
&lt;option value="shielding"&lt;?=$list == "shielding" ? 'selected' : '';?&gt;&gt;Shielding&lt;/option&gt;
&lt;option value="distance"&lt;?=$list == "distance" ? 'selected' : '';?&gt;&gt;Distance&lt;/option&gt;
&lt;option value="melee"&lt;?=$list == "sword" ? 'selected' : '';?&gt;&gt;Melee&lt;/option&gt;
&lt;option value="fishing"&lt;?=$list == "fishing" ? 'selected' : '';?&gt;&gt;Fishing&lt;/option&gt;
&lt;/select&gt;
You can use a lookup table for your values like this:

$values = array("magic" =&gt; "Magic points", ...);


and then loop over that to reduce the duplication:

foreach ($values as $key =&gt; $value) {
    ...