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

Mohammad Rifqi
PLUS
Mohammad Rifqi
Courses Plus Student 3,218 Points

Array Keys code Challage 1 of 2

Bummer! Something's not quite right: you are loading book titles into a variable named $isbn. (Here's a clue: you should be using a double arrow.)

$books=array();
$books["978-0743261690"] = array(
      "title" => "Gilgamesh" ,"ISBN" => "978-0743261690");
$books["978-0060931957"] = array(
      "title" => "The Odyssey","ISBN" => "978-0060931957");
$books["978-0192840509"] = array(
      "title" => "Aesop's Fables", "ISBN" => "978-0192840509");
$books["978-0520227040"] = array(
      "title" => "Mahabharta", "ISBN" => "978-0520227040");
$books["978-0393320978"] = array(
      "title" => "Beowulf", "ISBN" => "978-0393320978");

?><html>
<head>
    <title>Five Great Books</title>
</head>
<body>
    <h1>Five Great Books</h1>
    <ul>
        <?php foreach($books as $book=> $isbn) { ?>
            <li><?php echo $isbn["ISBN"]; ?></li>
        <?php } ?>
    </ul>
</body>
</html>
Mohammad Rifqi
Mohammad Rifqi
Courses Plus Student 3,218 Points

im quite confused, i try on my own and it's work...

I would greatly appreciate for any help :)

2 Answers

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Sorry, I didn't check Challenge before. You don't need modify an array. You just need to display keys:

<?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 $isbn; ?></li>
        <?php } ?>
    </ul>
</body>
</html>
Mohammad Rifqi
Mohammad Rifqi
Courses Plus Student 3,218 Points

i try just display keys and still give an error error: Bummer! Something's gone haywire. I don't see any of the book titles in the browser anymore.

Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Then you need to display also book titles:

<?php foreach($books as $isbn=> $book) { ?>
            <li><?php echo $isbn." ".$book; ?></li>
<?php } ?>
Sergey Podgornyy
Sergey Podgornyy
20,660 Points

Try to switch names of key-value variables:

<ul>
        <?php foreach($books as $isbn => $book) { ?>
            <li><?php echo $book['ISBN']; ?></li>
        <?php } ?>
    </ul>
Mohammad Rifqi
Mohammad Rifqi
Courses Plus Student 3,218 Points

error: Bummer! Something's gone haywire. I don't see any of the book titles in the browser anymore.

still not work... it's want the '$book' after 'as', other wise it give an error

Mohammad Rifqi
Mohammad Rifqi
Courses Plus Student 3,218 Points

this code work, thanks Sergey Podgornyy

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