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

Arrays Forum

View Course » View Exercise

306 points
537263d29c4e9da6dd000a94_688363620
Submitted by
aleah78
about 3 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;

<?php
$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

permalink

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

Do you understand?

6455 points
52def2869c4e9d5f55000716_359294020
Submitted by
Gabriel La Rotta
about 3 years ago

3 Comments

537263d29c4e9da6dd000a94_688363620 aleah78 about 3 years ago

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

Picture Gilberto Netto almost 3 years ago

how I do shit issa ta very difficult Array Syntax

52def2869c4e9d5f55000716_359294020 Gabriel La Rotta almost 3 years ago

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