1 回答

TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊
在 $testing 中已經(jīng)有了這個(gè)結(jié)構(gòu):
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 關(guān)注
- 160 瀏覽
添加回答
舉報(bào)