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

Associative Array Code Challenge - too many elements?

I have gotten to the code challenge up to task five just fine (I think). Then as soon as I add the code that is supposed to add three more elements I get an error message reading:

"Bummer! Your array has too many elements. It should have five elements."

but as far as I can see I only added three elements??

<?php
    $movie = array ("");
    $movie[title] = "The Empire Strikes Back";
    $movie[year] = 1980;
    $movie[director] = "Irvin Kershner";
    $movie[imdb_rating] = 8.8;
    $movie[imdb_ranking] = 11;
?>

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

Help please!

3 Answers

<?php
$movie = array();
$movie['title'] = "The Empire Strikes Back";
$movie['year'] = 1980;
$movie['director'] = 'Irvin Kershner';
$movie['imdb_rating'] = 8.8;
$movie['imdb_ranking'] = 11;
?>
<h1><?php echo $movie['title']; ?> (<?php echo $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>

You made the mistake of adding "" in your array that should have been empty.

$movie = array("");

which turned your entire $movie array into

$movie = array(0 => "", 'title' => 'The Empire Strikes Back', 'year' => 1980, 'director' => 'Irvin Kershner', 'imdb_rating' => 8.8, 'imdb_ranking' => 11);

So your array actually had 6 elements, rather than 5.

oh! thanks!!!

Did that work you mark Harpreet Dhillon a great answer

Yes it did work. I'm not sure what you are asking?