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
Tony McCabe
8,445 PointsAssociative array challenge 6 of 7
Add three more elements to the array: (1) one with a key of "director" and a value of "Irvin Kershner", (2) one with a key of "imdb_rating" and a value of 8.8, and (3) one with a key of "imdb_ranking" and a value of 11. Here is my code: What's wrong? $movie["title"] = "The Empire Strikes Back"; $movie["year"] = 1980; $movie["director"] = array( "imdb_rating" => 8.8, "imdb_ranking => 11' );
10 Answers
Randy Hoyt
Treehouse Guest TeacherThis is what it's looking for:
$movie["title"] = "The Empire Strikes Back";
$movie["year"] = 1980;
$movie["director"] = "Irvin Kershner";
$movie["imdb_rating"] = 8.8;
$movie["imdb_ranking"] = 11;
Randy Hoyt
Treehouse Guest TeacherOh no! You have created a multi-dimensional array ... an array within an array. The universe is about to collapse on itself!!!!
Actually, it's not that bad. (We'll discuss how to do it on purpose in the next video, I think.) What you want is this:
$movie["director"] = ____;
It shouldn't be an array; it should be a piece of text with the director's name.
Does that help?
Tony McCabe
8,445 PointsDone that still $movie["director"] = ____; and it still say's somethings wrong I double and triple checked everything and same.
Randy Hoyt
Treehouse Guest TeacherThere are two different ways to create an associative array in PHP, and I think you might be conflating them. Here are the two different ways:
One way:
<?php
$movie["title"] = "The Empire Strikes Back";
$movie["year"] = 1980;
$movie["director"] = "Irvin Kershner";
$movie["imdb_rating"] = 8.8;
$movie["imdb_ranking"] = 11;
?>
Another way:
<?php
$movie = array(
"title" => "The Empire Strikes Back",
"year" => 1980,
"director" => "Irvin Kershner",
"imdb_rating" => 8.8,
"imdb_ranking" => 11
);
?>
The first way adds one new element to the array with each command. The second way creates the whole array (with all of the elements in it) in one command.
Hope that helps!
Dennis Hegstad
Courses Plus Student 2,243 PointsRandy - I'm attempting this same step and having some issues. What is wrong with my code?
<?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>
Randy Hoyt
Treehouse Guest TeacherHey Dennis Hegstad , It looks like you are missing a closing parenthesis. You probably have the following showing up in the preview:
The Empire Strikes Back (1980
It needs to have that closing parenthesis at the end:
The Empire Strikes Back (1980)
Does that help?
Tony McCabe
8,445 Pointsyep it work I just retyped everything and Kazam! it worked!
Tony McCabe
8,445 PointsI tried that way, but same now I'm working on 7 of 7.
Tony McCabe
8,445 PointsI'll try again? Thank you so much for your support?
clint cotchobos
6,593 Pointshelp <?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>
Leonard Foster
14,806 Pointsthis is what I posted and its saying "Bummer! your array does not have an element with a key of 'imbd_rating'. "
<?php
$movie = array(
"title"=> "The Empire Strikes Back",
"year" => "1980",
"director" => "Irvin Kershner",
"imbd_rating" => "8.8",
"imbd_ranking" => "11",
)
?>
<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>
<table>
<tr>
<th>Director</th>
<td><?php echo $movie["director"]; ?></td>
</tr>
<tr>
<th>IMBD Rating</th>
<td><?php echo $movie["imbd_rating"]; ?></td>
</tr>
<tr>
<th>IMDB Ranking</th>
<td><?php echo $movie["imbd_ranking"]; ?></td>
</tr>
</table>```
Daniel Eshetie
17,657 Pointsremove the coma from "imbd_ranking" => "11",
Boy Buijsman
13,773 PointsYours says: imbd_rating but needs to be imdb_rating
Katiuska Alicea de Leon
10,341 Points^^Exact thing happened to me