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

Arrays Forum

View Course

273 points
14dc9bdfe33029f550e78754c4abfcd5?s=140&d=retro
Submitted by
gplux
almost 2 years ago

Help! Section 4/7 isn't working

The assignment is to "Use echo to output the third item in $tens." Below is my code. Why isn't it working?!

    $tens = array(10, 20, 30, 40, 50);
    echo $tens[40]

Guys, please help, I really want to continue this course :(


0 votes

permalink

you want to output the contents of the 4th element. array index starts at 0.
0 = 10
1 = 20
2 = 30
3 = 40
4 = 50

so echo $tens[3] will give you the 4th element.

762 points
55dcb19395e378e83600022f_404522167
Submitted by
Jason Rez
almost 2 years ago


0 votes

permalink

Hi Jason, tnx for the answer! During the brief moment that the PHP course was functioning ("Trying in 2 seconds" error), I put in $tens[3]. It didn't work. It was only untill I put in $tens[2] that I could continue. To me, this makes no logical sense. The fourth element should either be 3 or 40, right? Why 2?!

273 points
14dc9bdfe33029f550e78754c4abfcd5?s=140&d=retro
Submitted by
gplux
almost 2 years ago

2 Comments

Picture Costin Ionut almost 2 years ago

They asked you the third element, not the fourth.. So $tens[2] is correct..

54e05f89937676d117005fbf_950379676 smokeyjones over 1 year ago

use
echo $tens{2};
using the square brackets is not working in this exercise, most likely a typo in the correction engine


0 votes

permalink

use
echo $tens{2};
using the square brackets is not working in this exercise, most likely a typo in the correction engine

779 points
54e05f89937676d117005fbf_950379676
Submitted by
smokeyjones
over 1 year ago