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 trialAndres Vicente
1,665 PointsWithout setting the entire array directly, remove the element with the value "Green".
no longer passed. i dont know wat is wrong with my code.
<?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);
2 Answers
Damien Watson
27,419 PointsHi 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);
Damien Watson
27,419 PointsAnd yes, as Andrew said, 'unset()
' also does the trick. :)
Samandar Mirzayev
11,834 Pointsu have to check by var_dump($colors) and u will see what's wrong there
Andrew Dovganyuk
10,633 PointsAndrew Dovganyuk
10,633 Pointsuse the code
unset($colors[2]);
Thats how you remove the value whatch again https://teamtreehouse.com/library/removing-array-elements