lgt lgt - 1 year ago 82
HTML Question

2D php array into an HTML table

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

Server1 db_1

Server1 db_2

Server1 db_3

Server2 db_1

Server2 db_2

Server3 db_3

Answer Source

Like this?

$servers = array(
    'Server 1' => array(
    'Server 2' => array(
    'Server 3' => array(
echo '<table>';
foreach($servers as $server=>$dbs)
    foreach($dbs as $db)
        echo '<tr><td>'.$server.'</td><td>'.$db.'</td></tr>';
echo '</table>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download