Creating an HTML table from array elements : HTML Table « HTML « PHP






Creating an HTML table from array elements

 
<?
    $languages = array ("a" => "A",
                        "b" => "B",
                        "q" => "Q");
    
    print "<table>";
    reset ($languages);
    $hd1 = key ($languages);
    $hd2 = $languages[$hd1];
    print "<tr><th>$hd1</th><th>$hd2</th></tr>";
    next($languages);
    
    while ( list ($ctry,$lang) = each ($languages)) :
         print "<tr><td>$ctry</td><td>$lang</td></tr>";
    endwhile;
    
    print "</table>";
?>
  
  








Related examples in the same category

1.Output a HTML table
2.Use for each to loop through an array and create a table
3.Separate the city and state name in the array so we can total by state