Jump to content

foreach printing in html table


audittr180

Recommended Posts

I want to print in an html table the Seasons,the Months,and the days of each month.

the following code prints the seasons and the days

i need another foreach in between that prints the months also

Any ideas???

Please help...

 

$seasons=array (

"Fall"=> array ("September"=>"30","October"=>"31","November"=>"30"),

"Winter"=> array ("December"=>"31","January"=>"31","February"=>"28"),

"Spring"=> array ("March"=>"31","April"=>"30","May"=>"31"),

"Summer"=> array ("June"=>"30","July"=>"31","August"=>"31")

);

$tab =  "<table border=\"1\">";

foreach($seasons as $season => $months) {

$tab .= "<tr><td colspan=\"4\">$season</td></tr>" ;

$tab .= "<tr>" ;

foreach($seasons[$season] as $days) {

$tab .= "<td>$days</td>" ;

}

$tab .= "</tr>" ;

}

$tab .= "</table>" ;

echo $tab ;

Link to comment
https://forums.phpfreaks.com/topic/237756-foreach-printing-in-html-table/
Share on other sites

try this?

$seasons=array (
   "Fall"=> array ("September"=>"30","October"=>"31","November"=>"30"),
   "Winter"=> array ("December"=>"31","January"=>"31","February"=>"28"),
   "Spring"=> array ("March"=>"31","April"=>"30","May"=>"31"),
   "Summer"=> array ("June"=>"30","July"=>"31","August"=>"31")
);
$tab =  "<table border=\"1\">";      
foreach($seasons as $season => $dates) {
   $tab .= "<tr><td colspan=\"4\">$season</td></tr>" ;
   $tab .= "<tr>" ;
   foreach($dates as $months=>$days) {
      $tab .= "<td>$months $days</td>" ;
   }
   $tab .= "</tr>" ;
}
$tab .= "</table>" ;
echo $tab ;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.