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

For Loops in PHP Forum

View Course » View Exercise

867 points
52bf57d9631fe9217d002e32_750892378
Submitted by
Ibrahim Ismail
about 4 years ago

All on Your Own!

So I typed

    <?php
    $yardlines = array("The 50... ", "the 40... ",
    "the 30... ", "the 20... ", "the 10... ");
    // Write your foreach loop below this line
    foreach ($yardlines as $touchdown){

    // Write your foreach loop above this line
    echo $touchdown;
    }
  ?>
And it prints the whole thing but it keeps saying:
'Oops, try again! It looks like your loop didn't echo 'the 10...'

3 votes

permalink

Hi Ibrahim;
What you need to do is add, 'echo $touchdown!' within the curly braces (or whatever you wish to assign/call "$yardlines"). This tells the loop you want it to go through each element in the array, print the result on screen and stop there; by moving the curly braces at the bottom of the second "touchdown!" to it.

Now, you need type nothing more, the code is complete. Just run it!!
This is what you're doing; You're telling the computer to go the first, 'touchdown' array and print it on screen. Afterwards, just print the string, "touchdown!".

564 points
741be002f9cea2ae92f4cbb7a73ba975?s=140&d=retro
Submitted by
rabbit01
almost 4 years ago

2 Comments

52bf57d9631fe9217d002e32_750892378 Ibrahim Ismail almost 4 years ago

Thanks for the explanation! Here's a 1 up!

52eaed6752f86324400008c4_751627060 yodudo almost 4 years ago

make that 2 up


1 vote

permalink

Same here!! I'm still confused! ;-S

854 points
523b0eaa80ff3337ac0055cb_154198639
Submitted by
RexGalilae
almost 4 years ago