Please help me figure out why only 1 of the array items is being printed!


#1

This is what is being printed to the editor:

I love the book Naked and also the following books:
Franny and Zoey by JD Sallinger

I have no idea why it is skipping the first two items in the array.

This is my code:

<html>
  <head>
    <title>I am the King of Arrays!</title>
  </head>
  <body>
    <p>
      <?php
      // On the line below, create your own associative array:
    $myArray = array('David Sedaris' => 'Naked',
                     'Dante' => 'Inferno',
                     'JD Sallinger'=>'Franny and Zoey');

      // On the line below, output one of the values to the page:
     echo 'I love the book '.$myArray['David Sedaris'].' and also the following books: <br />';
          
      // On the line below, loop through the array and output
      // *all* of the values to the page:
         foreach($myArray as $author=>$book);
         echo $book.' by '.$author.'<br />'; 
             
     
      ?>
    </p>
  </body>
</html>

#2
    foreach($myArray as $author=>$book);
    echo $book.' by '.$author.'<br />';

foreach requires a code block. You have a misplaced ;.

    foreach($myArray as $author => $book) {
         echo $book . ' by ' . $author . '<br />'; 
    }

For readability, leave some white space around the operators.