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 Arrays and Control Structures PHP Arrays Modifying Arrays

Corey Maller
Corey Maller
4,076 Points

Task not working

This code should work but it's not

index.php
<?php

$colors = array("Red","Green","Blue");

//add modifications below this line

$colors[0] = "Magenta";
$colors[2] = "Cyan";

2 Answers

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,860 Points

Hi Corey,

I'm not sure which Task you are on, but I don't see the code for the First Task? The first task wants you to

add "Yellow" to the beginning of the array. Then add "Black" to the end of the array.

But don't see that code. Challenges are incremental, so each task builds on the previous. So, if you are on the first Task, then you're a bit off from the instruction... if you're on the 2nd task, you'll need to add back in the code from Task 1.

Hope that helps. :)
Keep Coding! :dizzy:

The index for the array changed because you added yellow and black. This worked:

$colors[1] = 'Magenta';
$colors[3] = 'Cyan';