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

Don Shipley
Don Shipley
19,488 Points

challenge task 3 of 7

What am I suppose to do? Do not understand how to keep the same or change the variable in a key

5 Answers

Tom Schinler
Tom Schinler
21,052 Points

The code should look like this

<?php
$movie = array(
    "title" => "The Empire Strikes Back"
);
?>

^ this is the array

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

and this should be what the first level header looks like. When you echo out $movie and pass in the key of ["title"] the server is going to add the appropriate html.

Don Shipley
Don Shipley
19,488 Points

Thank you I will give that a try..

Tom Schinler
Tom Schinler
21,052 Points

Hey Don, It seems this part of the challenge is asking you to replace the title of the movie currently in the <h1></h1> tags with the name of the movie stored in the php array. Try replacing what is inside of the H1 tags with a php code block echoing the name of the film inside the array.

Don Shipley
Don Shipley
19,488 Points

If I place this code it reads, Bummer! The title of the second movie is not displayed in the <h1>. if this <h1<?php $movie["title"], "Back to the Future (1985)" ; ?></h1> Bummer! The title of the second movie is not displayed in the <h1>. This <?php $movie = array(); $movie["title"] = "The Empire Strikes Back"; $movie[] = "Back To The Future (1985)"; foreach ($movie as $newMovie){ ?> <h1><?php echo $newMovie; ?></h1> <?php } ?> reads Bummer! It looks like the title of the second movie is in the <h1>, but something else isn't quite right. Double-check the parentheses and the year.

Don Shipley
Don Shipley
19,488 Points

Re watched the videos several times. I do not know how to create a key than change the variable to read without creating a new key.

Don Shipley
Don Shipley
19,488 Points

That worked I did something wrong. Thank you very much