PHP/HTML/HTML Table
Содержание
Creating an HTML table from array elements
<source lang="html4strict">
<?
$languages = array ("a" => "A", "b" => "B", "q" => "Q");print "
$hd1 | $hd2 |
---|---|
$ctry | $lang |
?>
</source>
Output a HTML table
<source lang="html4strict">
<html> <head> <title>Table Example</title> </head> <body>
$CarId[$x] | "; print "$Cars[$x] |
</body> </html>
</source>
Separate the city and state name in the array so we can total by state
<source lang="html4strict">
<? $population = array("New York" => array("state" => "NY", "pop" => 8008278),
"San Antonio" => array("state" => "TX", "pop" => 1144646), "Detroit" => array("state" => "MI", "pop" => 951270));
$state_totals = array(); $total_population = 0;
print "City | Population |
---|---|
$city, {$info["state"]} | {$info["pop"]} |
$state | $pop | \n";
Total | $total_population |
?>
</source>
Use for each to loop through an array and create a table
<source lang="html4strict">
$population = array("New York, NY" => 8008278,
"Los Angeles, CA" => 3694820, "Chicago, IL" => 2896016);
$total_population = 0;
print "City | Population |
---|---|
$city | $people |
Total | $total_population |
</source>