Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

PHP Array Keys Challenge HTML is not quite right

Hi, I can't seem to get my code, which looks like it's displaying perfectly, to pass this challenge. Any help would be appreciated.

Next, modify the code inside the foreach loop to display the $isbn in parentheses. After the title, add a space, an opening parenthesis, the ISBN, and a closing parenthesis.

Bummer! The HTML for this page is not quite right: <html><head><title>Five Great Books</title></head><body><h1>Five Great Books</h1><ul><li>Gilgamesh (978-0743261690)</li><li>The Odyssey (978-0060931957)</li><li>Aesop's Fables (978-0192840509)</li><li>Mahabharta (978-0520227040)</li><li>Beowulf (978-0393320978)</li></ul></body></html>


$books["978-0743261690"] = "Gilgamesh";
$books["978-0060931957"] = "The Odyssey";
$books["978-0192840509"] = "Aesop's Fables";
$books["978-0520227040"] = "Mahabharta";
$books["978-0393320978"] = "Beowulf";

?><html>
<head>
    <title>Five Great Books</title>
</head>
<body>
    <h1>Five Great Books</h1>
    <ul>
      <?php foreach($books as $isbn => $book) {
          echo"<li>" . $book . " (" . $isbn . ")</li>";
        } ?>
     </ul>
</body>
</html>

Note: I've also tried

  <?php foreach($books as $isbn => $book) { ?>
      <li><?php echo $book . " (" . $isbn . ")";?></li>
  <?php  } ?>

with the same results.

Very weird.

What is the link to the challenge?

1 Answer

I tried the challenge and did the following and it took it:

    <ul>
        <?php foreach($books as $isbn=>$book) { ?>
            <li><?php echo $book . " (".$isbn.")"; ?></li>
        <?php } ?>
    </ul>

I also proceeded to test your code...and it took it as true...

<?php foreach($books as $isbn => $book) {
          echo"<li>" . $book . " (" . $isbn . ")</li>";
        } ?>

I also tried your 'tried' code and it worked for me too...

    <ul>
      <?php foreach($books as $isbn => $book) {
          echo"<li>" . $book . " (" . $isbn . ")</li>";
        } ?>
     </ul>

I would try maybe refreshing your page and trying again?

You should add the $isbn=> then add the ($isbn). I have no idea why it is not working for you.

I feel like an idiot for not refreshing the page before. (Cue voice of Roy telling me to turn it off and on again.)

It does work now that I refreshed. I'm just glad I wasn't overlooking something simple that I just couldn't see. Thanks!

No problem! Glad I could help. If you have any more questions, feel free to post them on the forums!