0

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
1
  • I started as it follows $servers = array(Server1=>array('db_1','db_2','db_3'),Server2=>array('db_1','db_2','db_3'), ); but I don't know how to loop to have the desired result Commented Sep 24, 2011 at 9:49

1 Answer 1

2

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>';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.