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

Array Keys Challenge stage two

Hey guys,

I am stuck on Stage Two of this Array Key... I'm getting this return:

Bummer! I see all the book titles and the ISBNs in the browser, but the formatting is not quite right. Each list item should look like this: Book Title (978-0123456789)

The code that I have created is:

<?php

$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) { ?> <li><?php echo $book.' '.'('. $isbn .')' ; ?> </li> <?php } ?> </ul> </body> </html>

The outcome :

Five Great Books

Gilgamesh (978-0743261690) The Odyssey (978-0060931957) Aesop's Fables (978-0192840509) Mahabharta (978-0520227040) Beowulf (978-0393320978)

:.{

What do the gods want from me?!

Kit

8 Answers

What should the output look like?

Hey Kit,

It looks like the original <li> tags are missing from the code challenge which might be messing up the formatting of the output. Try adding those <li> tags back into the foreach block and see if that helps ya.

Hey Kit,

It looks like the original <li> tags are missing from the code challenge which might be messing up the formatting of the output. Try adding those <li> tags back into the foreach block and see if that helps ya.

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Hey Kit,

It looks like this is a bug in the code challenge. I was expecting the closing </li> tag to appear right after the closing parenthesis, but you have added some spaces and a hard return there. It doesn't matter that you have added those: I'm being too strict in my check.

I'll fix the code challenge shortly, but you can pass it now if you change these two lines ...

        <li><?php echo $book.' '.'('. $isbn .')' ; ?>
        </li>

... to one line ...

        <li><?php echo $book.' '.'('. $isbn .')' ; ?></li>

Sorry for the trouble!

Randy,

Thank you so much for the feed back, I was nearly busting a vein trying to figure out why it wasn't working :}.. The videos are rocking, keep up the awesome tutorials!

Kit

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Excellent. Sorry again for the vein-busting trouble ... but I'm glad you are enjoying the tutorials! :~)

It's worth it! Would pop a few more just to make sure I have the syntax down ;]. One last question, for employers looking at prospective applicants' work, would something like this hinder consideration?

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

Not at all! :~) You can write your HTML (or generate it with PHP) like this ...

<ul>
    <li>Item One
    </li>
</ul>

... or like this ...

<ul>
    <li>Item One</li>
</ul>

... without any difference.