如何通过PHP数组实现,在html表中得到以下结果:
Server1 db_1
Server1 db_2
Server1 db_3
Server2 db_1
Server2 db_2
Server3 db_3
答案 0 :(得分:2)
喜欢这个吗?
$servers = array(
'Server 1' => array(
'db_1',
'db_2',
'db_3'
),
'Server 2' => array(
'db_1',
'db_2'
),
'Server 3' => array(
'db_3'
)
);
echo '<table>';
foreach($servers as $server=>$dbs)
{
foreach($dbs as $db)
{
echo '<tr><td>'.$server.'</td><td>'.$db.'</td></tr>';
}
}
echo '</table>';