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.