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 Build a Basic PHP Website (2018) Listing and Sorting Inventory Items Associative Arrays

Alfredo Prince
Alfredo Prince
6,175 Points

Why is it asking: Did you assign a value to the "title" key?

I don't understand where I went wrong here.

index.php
<?php $movie = array();

$movie[] = ['title' =>"The Empire Strikes Back"];

?>

<h1>Back to the Future (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

Carlos Alberto Del Cueto Carrejo
Carlos Alberto Del Cueto Carrejo
13,817 Points

Remove the square brackets [ ] from $movie[], and leave it as just $movie,
This way PHP will add the value you are asking to the $movie variable that is already an array and creating a two Dimensional array or an Associative array, an array inside of an array. The way that you coded it is telling PHP to first create an array and then save the two dimensional array in the first index of the array, making it a three dimensional array. Hope this doesn't confuses you.

Devin Scheu
Devin Scheu
66,191 Points

I think it's because you double quoted the title value, but the key is single quoted.

It should look like this:

$movie[] = ['title' => 'The Empire Strikes Back'];
Carlos Alberto Del Cueto Carrejo
Carlos Alberto Del Cueto Carrejo
13,817 Points

First: Please forgive, how did you add the code to the comment O. O ? Second: The single and double quotes don't come into play in this scenario. I must admit it was the first thing I thought too.

Devin Scheu
Devin Scheu
66,191 Points

In order to comment on code you use the other key on the same button as ~ on your keyboard. Using 3 of these ticks with no spaces and typing the language after (Also without a spaces or a space between the ticks). Then you put your code and put another 3 of those tick to signify the block ending. I can't type the real character without it modifying my post.