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

Arrays Forum

View Course » View Exercise

146 points
Picture
Submitted by
Ali Bahrami
about 4 years ago

Access by Offset with [ ] problem

this is my code, i think it is okay but it echos error. can anyone help me?

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


8 votes

permalink

Same here:

Accessing Elements



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

130 points
72f8b515b5c76de89a7c50a4143915bb?s=140&d=retro
Submitted by
cantcode
about 4 years ago

4 Comments

72f8b515b5c76de89a7c50a4143915bb?s=140&d=retro cantcode about 4 years ago

I think its right, but it is saying its wrong... Then the site keeps saying "disconnected"

72f8b515b5c76de89a7c50a4143915bb?s=140&d=retro cantcode about 4 years ago

This is highly frustrating for somebody trying to learn to code - its hard enough as it is, and then other issues are thrown into the mix!

Come on guys fix this stuff!!!

6f528eb8574ae3395329fab55c285186?s=140&d=retro PanCoder about 4 years ago

Yeah that looks good. I've realised that it depends on the time of the day. Sometimes one just needs to press submit, make a small change (delete and retype) and submit again for it to re-submit - I think otherwise the browser ends up just staying idle. You will notice that every time one types something in, the small "console - sample browser" refreshes.

It should work at some point. I tend to work on two different lessons at the same time if the servers end up going funny just to use the time I have to read up on other stuff haha. Hope you got past it.

And yeah, it looks perfectly fine :).

Fbaf234270436c72387d16c9d3aee862?s=140&d=retro Samantha Ma about 2 years ago

works for me...


4 votes

permalink

Here is the solution

   <?php

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

    ?>

163 points
4f5f3eea99dca48d3dfdfcbf11b63f2e?s=140&d=retro
Submitted by
Steepfellow
almost 4 years ago

1 Comment

523e727fabf821ffc7005b29_130965968 empr24 over 3 years ago

<?php

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

?>

All you need to do is replace [ with { and ] with }.


2 votes

permalink

That should be fine, if its 30 you want to echo/print out. Its probably just the server that's lagging. Try refresh and then submit again (copy what you have so you can "repaste" it in :).

554 points
6f528eb8574ae3395329fab55c285186?s=140&d=retro
Submitted by
PanCoder
about 4 years ago

1 Comment

Picture Ali Bahrami about 4 years ago

Worked thanks :)


0 votes

permalink

It doesn't help that the instructions are cut off on the left and that there's no scroll to see the rest. Doh!

110 points
De2b71995a94a69fe50e88d73c4db63a?s=140&d=retro
Submitted by
mediabox101
about 4 years ago


0 votes

permalink

change echo to print

158 points
54f2e85451b8870e51003d8d_500498569
Submitted by
Joel Howe
about 2 years ago


-3 votes

permalink

Hi Guys,

I encountered a problem with this exercise last night. Did anyone manage find a solution?

Error message: "Oops, try again! It looks like you didn't print the correct value. Check the Hint if you need help!"

Code...

  <?php
    $tens = array(10, 20, 30, 40, 50);
    echo $tens[0];
  ?>

Thanks,

Robert

162 points
53908a84548c358b91000058_966701991
Submitted by
Robert Griffiths
about 4 years ago

1 Comment

9cab22fbb6e1489cbdfb2fa651fc26ab?s=140&d=retro Baxatronix over 3 years ago

look at the instructions they whant you to echo or print the third element of the array.not the first one. The first one is 10 and when u want to echo it you wrote 0 but they want third one so you have to echo $tens[2]