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 Listing Inventory Items Associative Arrays

PHP Track - Associative Arrays

I am doing the code challenge with associative arrays and can't figure out what I have done wrong. I didn't touch the first part of the code, and it sent me back to part 3/7 because it is now wrong. I copied it below, any help would be appreciated!

Challenge task 3 of 7 By the end of this code challenge, we'll REMOVE from the page all the information about the original movie ("Back to the Future") and REPLACE it with information about the new movie ("The Empire Strikes Back"). Right now, the <h1> element has the title of the original movie as a static piece of text. Replace that with a PHP command that INSTEAD displays the title of the new movie from the array. (Be sure to leave the <h1> tags, the parentheses, and the year intact.)

My answer: <?php $movie = array( "title" => "The Empire Strikes Back", "year" => "1980" ); ?>

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

Thank you so much!

4 Answers

Christopher Hall
Christopher Hall
9,052 Points

Hi Amanda, Part 3 of this code challenge is looking for the h1 tags and the year in parentheses outside of the PHP tags, like so:

<h1><?php print $movie["title"]; ?> (1985)</h1>

Then in part 5 it asks you to add another set of PHP tags, like so:

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

I think this is where you were having problems, perhaps you tried to combine these into one statement.

Max Bailey
Max Bailey
8,245 Points

Hi Amanda,

Just a thought, but you don't need the () at the end of your closing PHP tags. Not sure if this is the problem.

Also, as of PHP 5.4, Arrays use square brackets. Try replacing the array(); with array[];

Adam Moore
Adam Moore
21,956 Points

Your code looks right to me. However, when I did this, I got ahead of myself and removed the old year in preparation for the rest of the challenge, and it told me something like what you are describing. I had to replace all of the old movie's info that we hadn't gotten to yet in the code challenge's instructions because I had deleted them, and that fixed my problem.

Hope this helps!

Thanks all! I started from Part 1 and redid it all, and it worked. I really appreciate it