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 trialSimingaye Dube
2,587 PointsReplace with a PHP command that instead displays the title of the new movie from the array. (Be sure to leave the .
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 and the year intact.)
<?php $movie = array ("title" => "The Empire Strikes Back");
?>
<h1><?php echo $movie = "title"; ?> (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>
1 Answer
Sean T. Unwin
28,690 Pointswhen you use the statement, <?php $movie = 'title' ?>
, you are setting the variable, $movie
as a String with the text, 'title'
.
What we want to do is retrieve, from the $movie
Array, the value of the key 'title'
.
In order to for this to happen we want to use the statement <?php echo $movie['title'] ?>
within the h1
tag.
When we want to to extract the value of a key from an Array we use square brackets and within the square brackets we want to include either the name of the key as a String or alternatively, we may use the index value (as an Integer) of the key. In the case of our Array, since there is only one item, we may use 0
since Arrays use zero as a starting point. Either way works and valid.
Simingaye Dube
2,587 PointsSimingaye Dube
2,587 Pointsthanks a lot Sean ive edited to that code but its not running is there any change i should do to he array itself?
Sean T. Unwin
28,690 PointsSean T. Unwin
28,690 PointsThe Array declaration is fine as it is. Would you mind pasting your updated code at the point in the Challenge where it is failing?