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 Basic PHP Website Listing and Sorting Inventory Items Associative Arrays

I'm not sure why the string 'title' in the $movie array is not printing on the page as a result of my lines 2 and 3.

I'm not sure why the string 'title' in the $movie array is not printing on the page as a result of my lines 2 and 3.

index.php
<?php 
echo '<h1>' . $movie["title"] , "(1985)" . '</h1>';
$movie = array( "title" => "The Empire Strikes Back")
  ?>
<table>
  <tr>
    <th>Director</th>
    <td>Robert Zemeckis</td>
  </tr>
  <tr>
    <th>IMDB Rating</th>
    <td>8.5</td>
  </tr>
  <tr>
    <th>IMDB Ranking</th>
    <td>53</td>
  </tr>
</table>

2 Answers

Meghan Tucker
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Meghan Tucker
Front End Web Development Techdegree Graduate 31,226 Points

There are a couple small things in the code to watch out for: 1) (I'm not certain) but I'm pretty sure that php works similarly to CSS or Javascript in that you must declare things before you use them. Try putting your variable declaration first, so that when you reference your variable later the program knows what to pull from (please correct me if I'm wrong about that). 2) you're missing a semicolon to end your statement on line 3 ($movie = array(blah, blah); . and 3) I'm not sure if you have to do this, but it worked for me to place the statement referencing the year and the movie in its own php tag inside the <h1> tags, rather than pulling the <h1> tags out from the html section and into the php section. My end result looked like this:

<?php
  $movie = array("title" => "The Empire Strikes Back");
?>
<h1><?php echo $movie["title"] ; ?> (1985)</h1>
<table>

Hope this helps! Happy coding.

It works now I needed all three of those tips for it to work