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 trialCRYSTAL MORRIS
Courses Plus Student 2,809 PointsPHP Notice: Undefined variable: isbn in c06af3c2-ff24-4afa-8512-35309da624e5.php on line 85
There Is No Line 85, I Have pit Double Arrows Everywhere Before After And In The Middle Of The Foreach
Challenge task 1 of 2 The array below contains a list of books. Each element in the array has the book’s title as its value and the ISBN as its key. Right now, the page is only displaying the book titles in the browser. In this code challenge, we will modify the page to also display each book’s ISBN. First, we need to make the keys from the books array accessible inside the foreach loop. Modify the foreach command so that, as it loops through the books, it loads the ISBN for each book into a working variable called $isbn.
<?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
$books = $isbn("978-0743261690" => "Gilgamesh", "978-0060931957" => "The Odyssey", "978-0192840509" => "Aesop's Fables", "978-0520227040" => "Mahabharta", "978-0393320978" => "Beowulf");
<?php foreach($books as $book) { ?>
<li><?php echo $book; ?>(<?php echo $books["$isbn"]; ?>)</li>
<?php } ?>
</ul>
</body>
</html>
2 Answers
Jeremy Germenis
29,854 PointsYou have an unnecessary "<?php" in your code next to the foreach loop
You create an array with array() not $variable(). This is the format of an array with a key: $arrayName = array("key" => "value") --> $books = array("978-0743261690" => "Gilgamesh");
Your foreach loop is only assigning your value and not the key and value: foreach($arrayName as $key => $value) --> foreach($books as $isbn => $title)
CRYSTAL MORRIS
Courses Plus Student 2,809 PointsThank You Jeremy :-)