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

David Moody
David Moody
19,302 Points

Is there an error with Treehouse's code challenge on PHP arrays?

The code challenge is telling me to add a key of "title" and a value of "The Empire Strikes Back."

I have added it this way:

$movie = []; //I have also tried $movie=array(); $movie[] = ["title" => "The Empire Strikes Back"]; //the attached code is a different variation of this

The code challenge keeps giving back the error: "Have you assigned a value to key 'title'?" I changed the code to what is attached now, and I see the new error message, "Did you assign the value of 'title' to 'The Empire Strikes Back'?"

I don't see my error, and I have re-watched the video. I don't see any missing semi-colons, etc.

Is it my error or Treehouse's coding challenge?

index.php
<?php
$movie = [];
$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>
David Moody
David Moody
19,302 Points

I had a similar problem that left me unable to finish a code challenge yesterday on multi-dimensional arrays in the class PHP Arrays and Control Structures.

1 Answer

Ryan S
Ryan S
27,276 Points

Hi David,

The problem is that you have defined the value to be assigned to "title" as an array. It is possible to do this, however it is not what the challenge is asking for. The value "The Empire Strikes Back" is just a single string, not an item in an array.

<?php
$movie = [];
$movie["title"] = "The Empire Strikes Back";
?>