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 PHP Basics (Retired) PHP Datatypes PHP Datatypes Challenge

$colors=arrays("red", "blue", "green"); question : using the $colors array, echo the second value..someone plz help

I am new with php can someone please assist me with this

$colors=arrays("red", "blue", "green"); question : using the $colors array, echo the second value..

i wrote : echo $colors[1] and it wouldnt accept it.

index.php
<?php

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

3 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Mind;

Welcome to Treehouse!

It looks like your Array code is correct and you are choosing the correct array item to display. The code challenge doesn't like things outputted it is not looking for, and as such if you remove your var_dump line your code works just fine. One of the things to remember as you work through the challenges here at Treehouse is to generally not add any extra code to them that is not requested. The challenge engine checker will generally reject your code.

Happy coding,

Ken

Thanks for your help.

Adam Young
Adam Young
15,791 Points

Your code is valid. Maybe you're getting an error because of the var_dump()?

<?php

//Place your code below this comment
$integer_one = 1;
$integer_two = 2;

$golden = 1.618;

$bool = true;

$colors = array('red', 'blue', 'green');

echo $colors[1];

?>

Works just fine for me.

Thanks for your help.

Hey Mind B,

Well, you do have a "var_dump()" execution going on that is unnecessary, and that is causing the Challenge to error out. You should get rid of the unnecessary var_dump execution and that will allow you to carry on in the challenge! :)

Thanks for your help.

My pleasure, Mind B! If you'd go ahead and select a Best Answer to this question, we'll go ahead and mark this as solved.