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

For Loops in PHP Forum

View Course » View Exercise

221 points
51310e25f519e1f70c00021e_855051864
Submitted by
Mukund Patwardhan
about 3 years ago

Oops, try again. It looks like your loop didn't echo 'The 50... '.

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


5 votes

permalink

<html>
  <head>
    <title></title>
  </head>
  <body>
    <p>
      <?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!";
      ?>
    </p>
  </body>
</html>

This code worked for me fine.
Shadab K
Weave and Connect

493 points
189c68618795f9cde350787221e4ec76?s=140&d=retro
Submitted by
Shadab Khatib
about 3 years ago

1 Comment

0d9aaae3955426da0b101632371490a1?s=140&d=retro pmhindurwa over 2 years ago

It worked for me too after a struggle. Just don't forget echo "touchdown!"; after the }


1 vote

permalink

Just add echo "touchdown" after the loop;

1063 points
53c4675c8c1ccc62f200295d_606240500
Submitted by
Stefano Bozzi
almost 3 years ago


0 votes

permalink

looks like you need match your syntax, I would recommend changing $touchdown to something else maybe $firstdown A bit confusing to read at first. as well

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

your could is probably just printing touchdown, it doesn't echo the items in the array

604 points
5304429580ff33ec65000bf5_478044083
Submitted by
Carey J. Mays
about 3 years ago

2 Comments

530f37b9282ae3a00100442d_251772262 Samak Aiden about 3 years ago

This is my php code but it still error -->

<?php
$yardlines = array("The 50... ", "the 40... ",
"the 30... ", "the 20... ", "the 10... ");

    foreach ($yardlines as $firstdown) {


    echo $firstdown;
    }
    unset($firstdown);
  ?>

5304429580ff33ec65000bf5_478044083 Carey J. Mays about 3 years ago

don't need to unset it


0 votes

permalink

foreach($yardlines as $y) {
echo $y;

}

word for me

604 points
5304429580ff33ec65000bf5_478044083
Submitted by
Carey J. Mays
about 3 years ago

2 Comments

51310e25f519e1f70c00021e_855051864 Mukund Patwardhan about 3 years ago

thanks!!
I tried this and it worked..

<?php
$yardlines = array("The 50... ", "the 40... ",
"the 30... ", "the 20... ", "the 10... ");
foreach ($yardlines as $yards) {
echo $yards;
}
echo "touchdown!"; ?>

52d6083c548c35bbf4000c02_525446410 bigkoala about 3 years ago

thx Mukund


0 votes

permalink

What About This !!! System Says Oops!! it's looks like your code dindn't echo the 10...

<html>
      <head>
        <title></title>
      </head>
      <body>
        <p>
          <?php
            $yardlines = array("The 50... ", "the 40... ",
            "the 30... ", "the 20... ", "the 10... ");
         foreach($yardlines as $y){   
         echo $y ;
         }
          ?>
        </p>
      </body>
 </html>

74 points
5337af909c4e9dd03e00555b_338391447
Submitted by
Namper The Hacktvist
about 3 years ago

1 Comment

5334931b9c4e9d6d0b000385_655939080 jiaxinzhang-i^2 about 3 years ago

happened to me too