title: PHP function to print table in HTML
body: <p>It is fairly easy to use PHP to generate HTML code to display a table (which is an array of arrays of equal length), for instance the code below. I was wondering however: is there a PHP function that does this for you? I searched Google on <code>print table in php</code> and searched the PHP manual on <code>table</code>, but could not find such a function.</p>
  
  <p>Code from <a href="http://davidwalsh.name/html-mysql-php" rel="nofollow">http://davidwalsh.name/html-mysql-php</a> to print a table:</p>
  
  <pre><code>$result2 = mysql_query('SHOW COLUMNS FROM '.$table) or die('cannot show columns from '.$table);
  if(mysql_num_rows($result2)) {
      echo '&lt;table cellpadding="0" cellspacing="0" class="db-table"&gt;';
      echo '&lt;tr&gt;&lt;th&gt;Field&lt;/th&gt;&lt;th&gt;Type&lt;/th&gt;&lt;th&gt;Null&lt;/th&gt;&lt;th&gt;Key&lt;/th&gt;&lt;th&gt;Default&lt;th&gt;Extra&lt;/th&gt;&lt;/tr&gt;';
      while($row2 = mysql_fetch_row($result2)) {
          echo '&lt;tr&gt;';
          foreach($row2 as $key=&gt;$value) {
              echo '&lt;td&gt;',$value,'&lt;/td&gt;';
          }
          echo '&lt;/tr&gt;';
      }
      echo '&lt;/table&gt;&lt;br /&gt;';
  }
  </code></pre>