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

STUCK ON TASK 5 OF 7 FOR ASSOCIATIVE ARRAYS PART II.

I know this question has been addressed in another forum, but there is so much information all over the place it's kind of hard to follow. So, here goes, can anyone tell me what i'm doing wrong here?

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

6 Answers

Why use multiple <?php tags? Wrap your code into:

<?php
    //code
?>

You could also concatenate them using

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

This outputs "The Empire Strikes Back (1980)"

Try to do like below, it may help you

 $movie = array(

      title => "The Empire Strikes Back",

      year => 1980

 );

Thanks guys I got it using Nicholas' code suggestion:

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

You should probably using Dai Phong's method. That is the associative way of doing it.

Yeah I actually did it that way too and was having was having problems so I just did it the basic way. That way is better though and I'll definitely use that method when writing code!

Try this instead, if you haven't passed it yet:

<?php

$movie = array( "title" => "The Empire Strikes Back", "year" => 1980 )

?>

<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>

Gave me green.