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, change the element value of "Red" to "Magenta" and the element value of "Blue

Could you find what is an error?

Bummer ; The array is not contain correct elements.

Thank you.

index.php
<?php

$colors = array("Red","Green","Blue");
array_unshift($colors, "Yellow");
array_push($colors, "Black");


unset($colors[1],$colors[3]);
$colors = array_values($colors);
$colors[1] = "Magenta";
$colors[3] = "Cyan";


//add modifications below this line

1 Answer

Hi you are close gj! Your being ask to change the values to “Magenta” and “Cyan” which you did ok. after that your being ask to delete only the key value with the element “Green” but you in this code deleted for some reason the second and the last element which that want required.

example: <?php

$colors = array("Red","Green","Blue"); array_unshift($colors, "Yellow"); array_push($colors, "Black");

//add modifications below this line $colors[1] = "Magenta"; $colors[3] = "Cyan"; unset($colors[2]);

t worked :)

THANK YOU SO MUCH.