1 回答

TA贡献1842条经验 获得超22个赞
在 $testing 中已经有了这个结构:
Array ( [Knight ] => Array ( [0] => Array ( [name] => Dave ) [1] => Array ( [name] => Simon ) ) [Lieutenant ] => Array ( [0] => Array ( [name] => Tom ) ) )
做表
<?php
// Just to keep same variable
$output = $testing;
?>
<table border=1>
<thead>
<tr>
<?php
// We need to know wich $title has more names
$max = 0;
foreach($output as $title => $names) {
if(count($names) > $max) {
$max = count($names);
}
?>
<th><?php echo $title;?></th>
<?php } // end foreach ?>
</tr>
</thead>
<tbody>
<?php
// Loop for creating table rows
for($i = 0; $i < $max; $i++) {
?>
<tr>
<?php
// Loop for creating table cells
foreach($output as $title => $names) {
?>
<td><?php
// Echo only if name exists
if(isset($names[$i]['name'])) {
echo $names[$i]['name'];
}
?></td>
<?php
} // end foreach
?>
</tr>
<?php
} // end for
?>
</tbody>
</table>
- 1 回答
- 0 关注
- 162 浏览
添加回答
举报