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 trialSofia Petsoulakis
681 PointsHaving trouble adding movie["year"] in parenthesis. Tried multiple ways, no sure what I'm doing wrong.
I keep getting errors, I even used a separate php command for the year and tried concatenated the parenthesis with the year. Any help would be appreciated so I can move forward. Thanks.
<?php
$movie = array(
"title" => "The Empire Strikes Back",
"year" => 1980
);
?>
<h1><?php echo $movie["title"]($movie["year"];) ?></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
Jason Anello
Courses Plus Student 94,610 PointsHi Sofia,
You have a few different ways you can handle this.
If you go with separate php blocks then you want to make sure that the parentheses are outside of the php blocks and that you have maintained spacing.
<h1><?php echo $movie["title"]; ?> (<?php echo $movie['year']; ?>)</h1>
Or you could do it with one php block and string concatenation.
<h1><?php echo $movie["title"] . ' (' . $movie['year'] . ')'; ?></h1>
I'd say the first one is probably more readable.
Schweine FEin
2,671 PointsI would say the concatenation is more readable but perhaps just because i'm used to it :D
Schweine FEin
2,671 PointsYou must use string concatenation and that works like this:
<?php
echo $movie["title"] . $movie["year"] ;
// output : "The Empire Strikes Back1980"
?>
For getting in the parentheses you just have to add more strings for concatenation:
<?php
echo $movie["title"] . ' (' . $movie["year"] . ')';
// output : "The Empire Strikes Back 1980"
?>
Well I wanted you to think about the actual solution yourself but that doesn't matter now since jason posted the full solution so I edited this as well
Schweine FEin
2,671 PointsDamm this code tags, well now I've got it xD
Schweine FEin
2,671 PointsSchweine FEin
2,671 PointsI know the answer was "The Empire Strikes Back (1980)" but this way you won't learn something. So I posted just a hint for you and with some thinking you would have figured it out ;) Just saying because of the comment you wrote and now is deleted.