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 Object-Oriented PHP Basics Building the Recipe Accessing Arrays

Joshua Mclendon
Joshua Mclendon
46,708 Points

I don't understand why this challenge isn't passing....

Keeps saying I'm echoing the wrong output when it's the right output? Idk help.

index.php
<?php

//Place your code below this comment
$colors = array();
array_push($colors, "red", "green", "blue");
echo $colors[1] . "\n";

$favorite_colors = array(
  "mike" => "green",
  "jane" => "blue",
  "chris" => "red"
);

echo $favorite_colors['mike'];

?>

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! It's correct that it's the incorrect output, but the reason here is somewhat mystifying. I had to go back and look carefully at this challenge. It should have failed you at Step 2, but not because of any syntax error.

In your $colors array, you were to add the items (in order) as red, blue, green. But you reversed the blue and the green and pushed "red, green, blue". Your first echo statement is then to echo out the second element of that. Yours echoes out green, but it should echo out blue.

Changing this:

array_push($colors, "red", "green", "blue");

To this:

array_push($colors, "red", "blue", "green");

... causes your code to pass all steps!

Hope this helps! :sparkles: