""/> "" /> "" /> "" /> "" />

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

Arrays Forum

View Course » View Exercise

608 points
Effbd0b8d8283b169b4a37a49cd52d23?s=140&d=retro
Submitted by
gledger_4fce1aada8cc9c0003057aa4_del
over 3 years ago

What is "=>"

Is it an operator? It wasn't in the php documentation. Why would I use it instead of just doing this:

$myColors = array("red", "green", "blue");
$myColors[2] = "yellow";
//#myColors should now contain "red", "green", "yellow"

?


1 vote

permalink

I don't think so. Where did you find it :) ,

valid operators are <= & >=

1302 points
6fe2f0b6d4bf3ab714ff3a1bd653cafb?s=140&d=retro
Submitted by
tulagak
over 3 years ago

2 Comments

Picture Cisco over 3 years ago

here <?php
array(0 => "red",
1 => "blue",
2 => "yellow");
?> on the exercise Modifying Array Elements

6fe2f0b6d4bf3ab714ff3a1bd653cafb?s=140&d=retro tulagak over 3 years ago

What they are doing I believe is explaining indexes in the array. first item in the array has index number 0, second one 1 , third one 2...... thus 0 => "red" , should mean red is the first item in the array at index 0.


1 vote

permalink

It is an assignment operator, like = , but for assigning value to named keys.

http://www.php.net/manual/en/language.operators.assignment.php

3692 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
over 3 years ago

1 Comment

Fb816ef8e77efe98533a183b2d8b7d73?s=140&d=retro diana_pencheva over 3 years ago

It is assignment operator for arrays.
For arrays, assigning a value to a named key is performed using the "=>" operator.
Also named key could be integer like 0,1,2 as in the example.


0 votes

permalink

http://www.php.net/manual/en/language.operators.array.php

I did not see it here but this may help

543 points
Picture
Submitted by
Cisco
over 3 years ago