This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by gplux
over 8 years

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 :(

Answer 55cf43d09376768d840004f8

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.

points
Submitted by Jason Rez
over 8 years

Answer 55d053239113cbdc740004d5

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?!

points
Submitted by gplux
over 8 years

2 comments

Costin Ionut over 8 years

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

smokeyjones over 8 years

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

Answer 55f880b7937676067400054b

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

points
Submitted by smokeyjones
over 8 years