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 trialShilpa Kothari
4,518 PointsPlease help
Can you please tell what is wrong in my code.
<?php
$books = array (
978-0743261690 => "Gilgamesh";
978-0060931957 => "The Odyssey";
978-0192840509 => "Aesop's Fables";
978-0520227040 => "Mahabharta";
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>
2 Answers
Jeff Lemay
14,268 PointsWhen you create the items in the array, you are supposed to use commas to separate each line, not semi-colons.
<?php
$books = array (
978-0743261690 => "Gilgamesh",
978-0060931957 => "The Odyssey",
978-0192840509 => "Aesop's Fables",
978-0520227040 => "Mahabharta",
978-0393320978 => "Beowulf"
);
?>
Shilpa Kothari
4,518 PointsThank you all everything is working.
Shilpa Kothari
4,518 PointsShilpa Kothari
4,518 PointsI Changed the semicolon into commas but now it is saying ISBN is not seen in the browser.
Mario Blokland
19,750 PointsMario Blokland
19,750 PointsHi,
leave the array as it was like this:
Jeff Lemay
14,268 PointsJeff Lemay
14,268 PointsI copy/pasted your code and got this error at first: Parse error: syntax error, unexpected ';', expecting ')' in C:\xampp\htdocs\today.php on line 4
Then I updated the array with commas instead of semi-colons and got this:
Five Great Books Gilgamesh (-1978812) The Odyssey (930) Aesop's Fables (977) Mahabharta (-88156750) Beowulf (975)
I assumed that was correct since it printed your foreach loop but just now I noticed the ISBNs aren't printing properly so I wrapped each key in quotes like it is a string and then got:
Five Great Books
Gilgamesh (978-0743261690) The Odyssey (978-0060931957) Aesop's Fables (978-0192840509) Mahabharta (978-0520227040) Beowulf (978-0393320978)