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 trialAndy Hughes
10,049 PointsI have tried these exercises and rewatched the videos but I'm still getting them wrong. How do i do it?
I am trying to change the film title using an array $movie["title"] = "The Empire Strikes Back". So I write my code as follows;
<?php echo "<h1>"$movie "(1985) </h1>"; ?>
but when I check the exercise, i'm getting it wrong. I have gone back to the videos but they just don't seem to correlate to what the exercise is asking me to do. I need help as I'm becoming increasingly frustrated with what feels like a mismatch between the videos and the exercises.
<?php
$movie["title"] = "The Empire Strikes Back";
?>
<?php
echo "<h1>"$movie "(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>
2 Answers
Jonathan Grieve
Treehouse Moderator 91,253 PointsHi there.
It looks like you're trying to cocatenate the value of an associative array to the start of another string, so join one thing to the other.
To do this you need the concatenation operator which is a period.
Try the following making sure you reference the array key.
<?php echo "<h1>" . $movie["title"] . "(1985) </h1>"; ?>
Daniel Stopka
13,520 PointsHi,
you can also leave h1 tag where it is and add php inside it, like this:
<h1><?php echo $movie["title"]; ?> (1985)</h1>
Andy Hughes
10,049 PointsThanks Daniel, I started messing around with the code on phpfiddle and sure enough, this was the solution I ended up at. It also seems like the simplest i.e. less code for syntax errors! :P
Thanks for your help.
Andy Hughes
10,049 PointsAndy Hughes
10,049 PointsSo close and yet so far! I don't remember seeing a video on concatenating the array, but it might be one I watched a while back. Thanks for your support, sorted now. :)