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

My answer is right and not being accepted

echo $favorite_colors["mike"];

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"];
?>

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hey Nicholas,

Yep, in syntax your answer is correct. However, it seems to be the order of the first array that is throwing the Bummer for the final task. I don't know why it only affects the last task.

The $colors array should be $colors = ['red', 'blue', 'green']; I'm not sure why it didn't "Bummer" when that particular task was being checked. (Challenges are picky, strict, and sometimes just wonky. :smile:)

Also, you will need to uncomment the first echo statement.

Fix those two things up and the code will pass all the Tasks.

Keep Coding! :dizzy:

Thanks Jason!

Joe Schultz
Joe Schultz
6,191 Points

The challenge did not say to comment out the echo $colors[1]; line. So put that back in and try again. If it still come up as being wrong, change the $colors line to $colors=['red','blue','green']; . That was the order that was requested. It should not be a factor, but I have seen stranger things with these challenges. Hope this helps!