开发者

2D php array into an HTML table

开发者 https://www.devze.com 2023-04-07 10:26 出处:网络
How can I achieve with a PHP array, to have as result in an html table the following result: Serv开发者_Go百科er1db_1

How can I achieve with a PHP array, to have as result in an html table the following result:

Serv开发者_Go百科er1          db_1

Server1          db_2

Server1          db_3

Server2          db_1

Server2          db_2

Server3          db_3


Like this?

$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>';
0

精彩评论

暂无评论...
验证码 换一张
取 消