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

Display value in associative array

My code seems to satisfy the requirements and displays the title on the browser, but teamtreehouse doesnt let me pass step 5 whats wrong?

index.php
<?php
$movie= array("title" => "The Empire Strikes Back",
                "year"=>"1980");
?>
<h1><?php 
  echo $movie["title"];
  echo " ".$movie["year"];
                ?></h1>

<h1>Back to the Future (1985)</h1>

<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>
Anton Klyuchkovksiy
Anton Klyuchkovksiy
8,327 Points

Hi! You can use one echo here ;)

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

1 Answer

Antonio De Rose
Antonio De Rose
20,884 Points

nothing wrong with the code, your argument is correct, it is working, I think sometimes, which am not 100 percent sure of, the treehouse parser, does not align with additional white spaces try the below

<?php
$movie= array("title" => "The Empire Strikes Back",
                "year"=>"1980");
?>
<h1><?php echo $movie["title"];echo " ".$movie["year"];?></h1>

<h1>Back to the Future (1985)</h1>

<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>