title: PHP foreach loop to populate dropdown list with values from an array of arrays
body: <p>I have an <strong>array of an arrays</strong> created using the following code. I'm trying to get this to loop through and populate a dropdown list. </p>
  
  <pre><code>$names = $db-&gt;fetchAll("select `name` from `classes`");
  </code></pre>
  
  <p>This is what is stored in the $names variable.</p>
  
  <blockquote>
    <p>Array ( [0] => Array ( [name] => Web Design ) [1] => Array ( [name] =>
    Art History ) [2] => Array ( [name] => Gym ) [3] => Array ( [name] =>
    English ) [4] => Array ( [name] => Biology ) [5] => Array ( [name] =>
    3D Animation ) [6] => Array ( [name] => Tech Disc ) [7] => Array (
    [name] => Math ) [8] => Array ( [name] => Dance ) [9] => Array (
    [name] => Video Production ) [10] => Array ( [name] => Home Ec ) [11]
    => Array ( [name] => Government ) [12] => Array ( [name] => Physics ) )</p>
  </blockquote>
  
  <p>I have this dropdown list created and it work, but it is hand coded for each value in the array. I want to modify this so it 'loops' through all results in the array to create the dropdown.</p>
  
  <pre><code>&lt;label for="per1"&gt;&lt;/label&gt;
  &lt;select name="per1" id="per1"&gt;
      &lt;option selected="selected"&gt;Choose one&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[0]['name'];?&gt;"&gt;&lt;?php echo $names[0]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[1]['name'];?&gt;"&gt;&lt;?php echo $names[1]['name'];?&gt;&lt;/option&gt;    
      &lt;option value="&lt;?php echo $names[2]['name'];?&gt;"&gt;&lt;?php echo $names[2]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[3]['name'];?&gt;"&gt;&lt;?php echo $names[3]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[4]['name'];?&gt;"&gt;&lt;?php echo $names[4]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[5]['name'];?&gt;"&gt;&lt;?php echo $names[5]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[6]['name'];?&gt;"&gt;&lt;?php echo $names[6]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[7]['name'];?&gt;"&gt;&lt;?php echo $names[7]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[8]['name'];?&gt;"&gt;&lt;?php echo $names[8]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[9]['name'];?&gt;"&gt;&lt;?php echo $names[9]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[10]['name'];?&gt;"&gt;&lt;?php echo $names[10]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[11]['name'];?&gt;"&gt;&lt;?php echo $names[11]['name'];?&gt;&lt;/option&gt;
      &lt;option value="&lt;?php echo $names[12]['name'];?&gt;"&gt;&lt;?php echo $names[12]['name'];?&gt;&lt;/option&gt;           
  &lt;/select&gt; 
  </code></pre>
  
  <p>Can someone please help?</p>