Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Listing Inventory Items Associative Arrays

Tingting Gu
Tingting Gu
9,779 Points

Could you tell me why I cannot pass task 5 of 7 on Stege 4(Listing inventory items) ?

I wrote codes as the follows but failed. Could you tell me why? <?php $movie = array( "title"=> "The Empire Strikes Back", "year" => 1985, "director" => "Robert Zemeckis", "rating" => 8.5, "ranking" => 53 );
?>

<h1><?php echo $movie["title"]. " (". $movie["year"]. ")"; ?></h1>

3 Answers

Lucas Santos
Lucas Santos
19,315 Points

Your array looks fine to me only thing I can think of maybe is that you have all double quotation in the echo statement below and I don't know why you are concatenating a white space after the movie year? try this instead

<?php echo $movie["title"] ." ('. $movie["year"]')"; ?>

Your code is correct, maybe is something else the problem. Is this the whole code for the challange or just a part of it?

I agree with George. My code is identical and it worked just fine. The only difference is I created two separate PHP statements on the same line inside the <h1> tag (one for the title key and one for the year key). This had me stuck for 3 days and I just solved it an hour ago.

<h1><?php echo $movie["title"];?><?php echo "(".$movie["year"].")"?></h1>

"This too shall pass" -_-