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 Build a Simple PHP Application Integrating with PayPal Array Keys

Integrating With paypal Challenge

I am having trouble completing part 2 of a code challenge. Here's what it is:

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.

I ended up creating new arrays for the $books var and this didn't do it. I am stuck and have watched the video again and again. Help por favor !! Thank you in advance

Can you attach the code that you are using?

8 Answers

sounds bad but I'm not sure how, just copy/paste?

Yeah just copy and paste.

Also surround your code with 3 backticks (```) so it will be formatted correctly.

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

I took care of the format for you.

Got it! still need help with the challenge though.

I already formatted your code.

When you are posting a comment, right under the text area you will see the bolded text "Markdown Cheatsheet". Click this for all markdown specifications.

formatted the code for the challenge? If so, where?

No in your comment :)

Hey Evan,

The code challenge is wanting you to load the ISBN for each book. In your case the ISBN is the key value of $books. You will need to use => in your foreach statement.

$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; ?></li>
        <?php } ?>
    </ul>
</body>
</html>

This is what I have after the first part of the challenge. It's the second part that gets me. I may be just not understanding the question right..

Hey Evan,

The code challenge was looking for a specific format of the return book title and ISBN. If the format wasn't exact then it would count your answer wrong.

This is how you create the desired format:

(SPOILER)

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

Thank you Calvin! Huge help. I appreciate it!

No problem Evan!

Have a nice day.