I'm trying to make a simple teaching schedule for myself and am stuck on the output of my array.

Here's the PHP:

```
echo '<table><thead><tr><th>Period</th><th>1</th><th>2</th><th>3</th>th>4</th><th>5</th><th>6</th><th>7</th><th>8</th><th>9</th></tr>';
echo '<tr><th>Time</th><th>08:50</th><th>09:40</th><th>10:30</th><th>11:20</th><th>12:10</th><th>13:00</th><th>13:50</th><th>14:40</th><th>13:30</th></tr>';
echo '</thead><tbody>';
$results = $db->mysql->query("SELECT * FROM schedule");
if ($results->num_rows) {
    while ($row = $results->fetch_assoc()) {
        $days[$row['day']][$row['period']] = $row['classroom'];
    } // close days while

    foreach ($days as $key => $val) {
        echo '<tr><td>' . $key .
            '</td>';
        foreach ($val as $item) {
            echo '<td>' . $item .
                '</td>';
        }
        echo '</tr>';
    }
}
echo '</tbody></table>';

```

This gives me an array like this: 

```
Array
(
[Monday] => Array
    (
        [1] => m5 biology
        [6] => m5 ict
        [8] => m6 ict
    )

[Tuesday] => Array
    (
        [3] => m5 biology
        [6] => m6 ict
        [7] => m6 ict
    )

[Wednesday] => Array
    (
        [1] => m6 biology
        [2] => m5 ict
        [7] => m5 biology
        [8] => m2 ict
    )

[Thursday] => Array
    (
        [1] => m6 biology
    )

[Friday] => Array
    (
        [1] => m6 biology
        [6] => m6 ict
    )

```

The table output looks like this:

```
...
<tr>
  <td>Monday</td>
  <td>m5 biology</td>
  <td>m5 ict</td>
  <td>m6 ict</td>
</tr>
...

```

What I would like is for the output to include empty table cells for the periods that are free. In the Monday example, there are only data for periods 1, 6, 8 so it only displays those cells.

How can I get this code to also output empty cells for periods 2,3,4,5,7,9? Like this:

```
...
<tr>
  <td>Monday</td>
  <td>m5 biology</td>
  <td>&nbsp</td>
  <td>&nbsp</td>
  <td>&nbsp</td>
  <td>&nbsp</td>
  <td>m5 ict</td>
  <td>&nbsp</td>
  <td>m6 ict</td>
  <td>&nbsp</td>
</tr>

```

I thought about using an if statement in foreach, but I can't figure out what kind of relationship I would need to make.

Any assistance would be greatly appreciated.