这个给你:
<?php
// [your array]
$tabledata = array(
'Media' => array(
'2012-12-10' => array(
'Mentor' => 'Evan Tobin',
'Veteran Member' => 'James'
),
'2012-12-21' => array(
'Mentor' => 'Evan Tobin'
)
),
'Website' => array(
'2012-12-10' => array(
'Mentor' => 'Evan Tobin'
),
'2012-12-21' => array(
'Mentor' => 'Evan Tobin'
)
)
);
// [/your array]
// [the tables]
echo '<table border="1">';
foreach($tabledata as $teamkey => $teamval){
// [helper]
$dates = array();
$roles = array();
foreach($teamval as $datekey => $dateval) {
if (!in_array($datekey, $dates)) {
$dates[] = $datekey;
}
foreach($dateval as $rolekey=>$roleval) {
if (!in_array($rolekey, $roles)) {
$roles[] = $rolekey;
}
}
}
// [/helper]
// [team name] >> row 1
echo '<tr>';
echo '<th align="left" colspan="'.(sizeof($dates)+1).'">'.$teamkey.' Team</th>';
echo '</tr>';
// [/team name]
// [role column and date column] >> row 2
echo '<tr>';
echo '<td>Role</td>';
foreach($dates as $date) {
echo '<td>'.$date.'</td>';
}
echo '</tr>';
// [/role column and date column]
// [role and team member for each date] >> row 3, 4, 5, ... n
foreach($roles as $role) {
echo '<tr>';
echo '<td>'.$role.'</td>';
foreach($dates as $date) {
echo '<td>';
if (isset($teamval[$date][$role])) {
echo $teamval[$date][$role]; // team member name
}
else {
echo ' '; // insert blank space for cross browser support
}
echo '</td>';
}
echo '</tr>';
}
// [/role and team member for each date]
}
echo '</table>';
// [/the tables]
如果您想为每个团队提供单独的表格,您可以将 放入循环中。
希望这可以帮助。