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

Without setting the entire array directly, remove the element with the value "Green".

no longer passed. i dont know wat is wrong with my code.

index.php
<?php

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

//add modifications below this line
array_unshift($colors, "Yellow");
array_push($colors, "Black");
$colors[1] = "Magenta";
$colors[3] = "Cyan";

array_pop($colors,  2,  1);

use the code

unset($colors[2]);

Thats how you remove the value whatch again https://teamtreehouse.com/library/removing-array-elements

2 Answers

Hi Andres,

In last challenge, you are calling the wrong array function. 'array_pop()' removes the last item from the array, not an item at the specified index. Try 'array_splice()' instead:

<?php

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

//add modifications below this line
array_unshift($colors, "Yellow");
array_push($colors, "Black");

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

array_splice($colors,  2,  1);

And yes, as Andrew said, 'unset()' also does the trick. :)

u have to check by var_dump($colors) and u will see what's wrong there