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

Johnathon Southworth
Johnathon Southworth
3,417 Points

What is happening

This is correct. So why is it not working?

index.php
<?php

//Place your code below this comment
$colors = ["red", "green", "blue"];

echo $colors[1];

$favorite_colors = ["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! You're doing great and there are no syntax errors. To be honest, I'm not sure exactly how this code passed the first few steps, but what's happening here is that your original $colors array contains the colors in the incorrect order which is making the final output greengreen instead of bluegreen which is clearly what they're checking for.

So this line:

$colors = ["red", "green", "blue"];

Should look like this:

$colors = ["red", "blue", "green"];

Note the reversal of blue and green between the two arrays. When I make that change, your code passes! Good luck! :sparkles:

Johnathon Southworth
Johnathon Southworth
3,417 Points

Goodness! Thank you! How silly. I was very flustered. Thanks for the timely response!