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

My array is not passing. Help!

I am working on Task 2 of 7 in the Build a Basic PHP Website course and thought this array I created would pass, but somehow it's not and I'm not sure what I'm doing wrong.

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>

3 Answers

Simon Coates
Simon Coates
28,694 Points

try

<?php
$movie = array();
$movie["title"] = "The Empire Strikes Back";

?>
<h1>Back to the Future (1985)</h1>

for task2. I've obviously ommitted some HTML, but you get the idea.

Simon Coates
Simon Coates
28,694 Points

To demonstrate the difference in the event of any uncertainty:

<?php

$movie = array();
$movie["title"] = "The Empire Strikes Back";
var_dump($movie);

$movie = array();
$movie[] = ["title" => "The Empire Strikes Back"];
var_dump($movie);
?>

produces:

array(1) {
  ["title"]=>
  string(23) "The Empire Strikes Back"
}
array(1) {
  [0]=>
  array(1) {
    ["title"]=>
    string(23) "The Empire Strikes Back"
  }
}

THANK YOU SIMON! Very helpful and thanks for your prompt reply. It's passing now. :)

Simon Coates
Simon Coates
28,694 Points

cool. i wasn't sure if your uncertainty was about the syntax or what exactly the test wanted. You might have been thinking of syntax like:

<?php
$movie = ["title" => "The Empire Strikes Back"];
?>
<h1>Back to the Future (1985)</h1>

It was the syntax that I was unclear on, but I was really trying to do too much. When I took a look at your answers, I simplified my approach and the syntax was then accurate. Your first answer showed me what I was missing.