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

Why isn't this working?? PHP Datatypes task 6 of 7. Echo $colors array

<?php

//Place your code below this comment $integer_one = 1; $integer_two = 2; $golden = 1.618; $bool = TRUE; $colors = ['red', 'blue', 'green']; echo $colors['green'];

?>

1 Answer

Erik McClintock
Erik McClintock
45,783 Points

David,

Without a link to your challenge, I'm not entirely sure what is being asked of you during this task, but I'm going to venture that you're being told to echo the color green from the colors array? If that's the case, the issue here is that you are trying to call a value from your array at an index called 'green', which doesn't exist. You don't have an associative array here (which would be an array with key => value pairs), you have an indexed array (just values, that live at numeric indices starting at 0). Thus, to call green from your array in this particular situation, you would want to call its index number, which is 2.

echo $colors[2];

Erik

nevermind I got it. You were on point it was just: echo $colors[1];

Thanks Erik!

Erik McClintock
Erik McClintock
45,783 Points

Thank you for the link. Now being able to see the task, I can see that it wants you to echo the second value from your indexed array, which would be at index 1 (whereas 2 would echo the third value, which corresponds to green in this instance).

Glad to have been of assistance! Please do make sure you link from the challenge or at least provide a link to it should you need help in the future!

Happy coding!

Erik