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 trialRex Irvin Carpen
3,314 PointsI just modify how come task 1 is no longer correct anymore
I just modify how come task 1 is no longer correct anymore?
<?php
$colors = array("Red","Green","Blue");
//add modifications below this line
array_unshift($colors, "Yellow");
array_push($colors, "Black");
array $colors["Red"] = "Magenta";
array $colors["Blue"] = "Cyan";
?>
1 Answer
Matthew Lang
13,483 PointsFirst of all, you do not need the 'array' keyword when editing the array. For example, you can simply do: $array[1] = "x";
$colors["Red"] = "Magenta";
This line of code is looking for the value with key of "Red" in the $colors array and changes it to Magenta. There is no set keys in the $colors array, therefore it uses an incrementing value from 0. For example, $colors[0] == "Yellow"
(after task 1, anyway)
Here is my code, that works.
<?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";
Rex Irvin Carpen
3,314 PointsRex Irvin Carpen
3,314 Pointsthanks Mathew Lang. I already get it now.