title: Whats the best way to show selected options on a form when reloaded using PHP
body: <p>I would like the select option the user selected to be shown when the form is reloaded. I am currently using bootstrap select picker to style the drop down. Right now I am creating an array and echoing out a selected class based on the value stored in the database. </p>
  
  <p>This is not a major problem with a small amount of options like the code provided below, however with a select box with larger amounts of options this obviously amounts to lots of extra code.</p>
  
  <p>There must be a smarter way to do this than the code i'm using below. Can anyone help?</p>
  
  <pre><code>&lt;select class="selectpicker" name="Do_You_Have_A_Job_Spec_You_Can_Email"&gt;
              &lt;option value="" &lt;?php if ($user_data_array['Do_You_Have_A_Job_Spec_You_Can_Email'] == '') echo "selected='selected'"; ?&gt;&gt;Please Select&lt;/option&gt;
              &lt;option value="Yes" &lt;?php if ($user_data_array['Do_You_Have_A_Job_Spec_You_Can_Email'] == 'Yes') echo "selected='selected'"; ?&gt;&gt;Yes&lt;/option&gt;
              &lt;option value="No" &lt;?php if ($user_data_array['Do_You_Have_A_Job_Spec_You_Can_Email'] == 'No') echo "selected='selected'"; ?&gt;&gt;No&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>