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

Arrays Forum

View Course » View Exercise

414 points
01f2117df4c3d511fb5c67aaa4c20dcd?s=140&d=retro
Submitted by
Aniket Verma
almost 3 years ago

Why wont this work??Always shows some error like did you replace [ ] with {} when i already have

<?php
$tens = array(10, 20, 30, 40, 50);
echo $tens{2} ;
?>


4 votes

permalink

You have a space after {2} take that space out and put ; right after {2}. It will work.
<?php
$tens = array(10, 20, 30, 40, 50);
echo $tens{2};

  ?>

1492 points
56231464b62548dd8200083b_338583113
Submitted by
Ellie Adam
almost 3 years ago


0 votes

permalink

You need to put {2} in normal braces, like [2].

456 points
5413bf9f52f863d440001775_767640641
Submitted by
Smash Boss
almost 3 years ago


0 votes

permalink

Insert a space after [2] eg: echo $tens[2] ;

638 points
542c54d67c82ca582f0011e2_765521661
Submitted by
menaka.siri
almost 3 years ago


0 votes

permalink

Very contradicting answers here. Fact 1: While using arrays, to access the index of the value, you type $arrayName[i] with i being the index position - 0 to however many items you have.

Fact 2: White space rarely matters and when it does, the accompanying code documentation will usually warn you of it. So, both $tens[2]; and $tens[2] ; and even $tens[2] ; will work just fine

438 points
4fb6fcef6ef03c0003022d66_274823844
Submitted by
smartalec
over 2 years ago


0 votes

permalink

I noticed the example shows print instead of echo, even though the previous exercise had you use echo. I had to change not just the braces, but echo to print as well.

590 points
Ed88418d56ffd23aaf638b6fc7718a7c?s=140&d=retro
Submitted by
tpiecora
over 2 years ago