<html>
<body>
<h1>Looping Through Arrays</h1>
<?php
$list1 = ['Sam', 'John', 'Joe', 'Sue', 'Steve', 'Stephanie'];
$list2 = ['Mon'=>'chicken', 'Tue'=>'beef', 'Wed'=>'fish',
'Thu'=>'veggie', 'Fri'=>'pizza', 'Sat'=>'pasta', 'Sun'=>'leftovers' ];
print_r($list1); //print_r dumps the array
print "<br /> \n";
print_r($list2);
print "<br /> <br/> \n";
print "<table border='2' width='100px'> \n"; //create an HTML table
print "<tr bgcolor='gray'><th> NAMES </th></tr> \n"; //print each name & value
for($i=0; $i < count($list1); $i++)
{
print "<tr><td> $list1[$i] </td></tr>"; //print each value
}
print "</table> <br>\n";
print "<table border='2' width='100px'> \n"; //create an HTML table
print "<tr bgcolor='gray'><th> NAMES </th></tr> \n"; //print each name & value
foreach ($list1 as $name)
{
print "<tr><td> $name </td></tr>"; //print each value
}
print "</table> <br>\n";
print "<table border='2' width='200px'> \n"; //create an HTML table
print "<tr bgcolor='gray'><th> DAY </th><th> MEAL </th></tr> \n"; //print each name & value
foreach ($list2 as $day => $food)
{
print "<tr><th> $day </th><td> $food </td></tr>"; //print each name & value
}
print "</table> <br>\n";
?>
<?php include "../include.php"; ?> <!-- hyperlink to see the code -->
</body>
</html>