This forum is now read-only. Please use our new forums at

Arrays Forum

View Course » View Exercise

306 points
Submitted by
about 4 years ago

What happens to items in an array if you modify it?

In the lesson, Modifying Array Elements, you are taught to add a new color to the array;

$myArray = array("red", "blue", "yellow");

echo $myArray[1];
// outputs "blue"

$myArray[1] = "green";

echo $myArray[1];
// outputs "green"

My question is does green replace blue in the array or does it just add green into the blue position and move the blue to the next position? What happens to blue?

0 votes


Hello, in the example green replaces blue, and the other elements (colors) of the array remain unchanged.

Do you understand?

6455 points
Submitted by
Gabriel La Rotta
about 4 years ago


537263d29c4e9da6dd000a94_688363620 aleah78 about 4 years ago

Yeah, I think so. I was confusing setting an element in an array because of the position. Thank you.

Picture Gilberto Netto about 4 years ago

how I do shit issa ta very difficult Array Syntax

52def2869c4e9d5f55000716_359294020 Gabriel La Rotta about 4 years ago

@Gilberto, it is not necessary to use vulgar language.