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

shubhamkt
shubhamkt
11,675 Points

Replacement syntax.

Elements are being replaced and passed om to the next element. Any Suggestions

index.php
<?php

$colors = array("Red","Green","Blue");
array_unshift($colors,"Yellow");
array_push($colors,"Black");
//add modifications below this line
$colors [0]= "Magenta";
$colors [2]= "Cyan";

var_dump($colors);

1 Answer

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Shubham,

There are a couple of problems. You need to remove the space between the array index and the value like so. Otherwise the code doesn't know you're trying to change the value.

<?php
$colors[1]= "Magenta";
$colors[2]= "Cyan";

Secondly you need to take into account that you've added new values to the array with push and unshift.

So try to imagine that you have 5 indexes in the array and not just the 3 and give the correct indexes in your answer. :-)

Good luck!