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

For Loops in PHP Forum

View Course » View Exercise

256 points
6827080ac72e64f04bfa419655018f68?s=140&d=retro
Submitted by
Mircea Lucian Albulescu
almost 4 years ago

Why my "foreach" code doesn't work?

This is what i wrote:

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

    // Write your foreach loop above this line
    echo $yard;
    }
  ?>

And it says "Oops, try again. It looks like your loop didn't echo 'the 10... '. But i see it printed!


0 votes

permalink

Try with this

foreach($yardlines as $touchdown){
echo $touchdown;}

141 points
657a34ef04b4d0045ba207a52e5cf8e5?s=140&d=retro
Submitted by
Ivan
almost 4 years ago

4 Comments

Feae3918e5391c5895a64978d923acd3?s=140&d=retro Sajeeva almost 4 years ago

i tried.. but i am getting the same response again =(

6827080ac72e64f04bfa419655018f68?s=140&d=retro Mircea Lucian Albulescu almost 4 years ago

yeap...it wanted at the end an echo "touchdown"...

6827080ac72e64f04bfa419655018f68?s=140&d=retro Mircea Lucian Albulescu almost 4 years ago

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

    // Write your foreach loop above this line
    echo $yard;
    }
    echo "touchdown";
  ?>

Feae3918e5391c5895a64978d923acd3?s=140&d=retro Sajeeva almost 4 years ago

thanku... it worked


0 votes

permalink

@Mircea Lucian : I'm also facing same issue, i tried the steps which you have mentioned above even then it's showing this error(Oops, try again. It looks like your loop didn't echo 'the 10... '.)

504 points
C188f80649bee537a698f6298f6335a8?s=140&d=retro
Submitted by
Satish Kumar
almost 4 years ago


0 votes

permalink

<?php
$yardlines = array("The 50... ", "the 40... ",
"the 30... ", "the 20... ", "the 10... ");
foreach ($yardlines as $yard) {
echo $yard;
}
echo "touchdown";
?>
// it should work...

256 points
6827080ac72e64f04bfa419655018f68?s=140&d=retro
Submitted by
Mircea Lucian Albulescu
almost 4 years ago

2 Comments

C188f80649bee537a698f6298f6335a8?s=140&d=retro Satish Kumar almost 4 years ago

Yeah i tried but did'nt work,

i proceeded by doing "'the 10..'" in the array it worked.

F9824b48a6426fbd867e0623dfde73bd?s=140&d=retro Dyo over 3 years ago

it was make me crazy i followed Satish Kumar step .. it woks! such a weird lesson....


0 votes

permalink

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

    // Write your foreach loop above this line
    echo "touchdown!";
  ?>

this is the answer

1077 points
52f5ba5a7c82caddbd0014c7_19534651
Submitted by
Super Rambo
almost 4 years ago