title: How can I set multiple default values in an HTML select control using the values in a PHP array?
body: <p>This is sort of an extension of the problem solved here: <a href="https://stackoverflow.com/questions/9710475/set-default-value-for-html-select-control-in-php">Set default value for HTML select control in PHP</a> however I would like to fill in Multiple values that match, with the values to fill in stored in an additional array: </p>
  
  <p>This is my code so far:</p>
  
  <pre><code>&lt;select name="genres[]" id="genres_edit" multiple&gt;
  &lt;?php
  $genrelist = array(  
  'Action',  
  'Adventure',
  'Comedy',
  'Cooking',
  'War',
  'Western');
  for($i = 0;$i &lt; count($genrelist);$i++) {
      echo "&lt;option value=\"$genrelist[$i]\"";
      for ($g = 0; $g &lt; count($genre);$g++) {
          if ($genrelist[$i] == $genre[$g]) {
              echo "selected=\"selected\"";
          }
      echo "&gt;$genrelist[$i]&lt;/option&gt;";
      }
  }
  ?&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>$genrelist is the array of all possible genres that will be used to fill up the select control, and the array of actual genres is stored in $genre. </p>
  
  <p>Basically I want it to highlight the values in the selectbox that match any of the values in the $genre array.</p>
  
  <p>i.e. if the genres stored in $genres are: Adventure, Cooking, Western, then those 3 values will be highlighted in the select box, out of the 6 available genres in the box.</p>