audittr180 Posted May 29, 2011 Share Posted May 29, 2011 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 ; Quote Link to comment https://forums.phpfreaks.com/topic/237756-foreach-printing-in-html-table/ Share on other sites More sharing options...
seanlim Posted May 29, 2011 Share Posted May 29, 2011 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 ; Quote Link to comment https://forums.phpfreaks.com/topic/237756-foreach-printing-in-html-table/#findComment-1221795 Share on other sites More sharing options...
audittr180 Posted May 29, 2011 Author Share Posted May 29, 2011 thnx a lot!!!!!! Quote Link to comment https://forums.phpfreaks.com/topic/237756-foreach-printing-in-html-table/#findComment-1221797 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.