Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP Build a Simple PHP Application Listing Inventory Items More Excitement With Arrays

task 5 of 7 build a simple php application

i don't know what is wrong with my code for this challenge!! can someone please help me? then it says task 4 no longer passes....

flavors.php
<?php

    $flavors = array ("Chocolate","Vanilla","Stawberry");


?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> 
  flavors of ice cream.</p>
<ul>
  <?php foreach($flavors as $flavor) {?>
      <li><?php echo $flavor1; ?> </li>  
      <li><?php echo $flavor2; ?> </li> 

  <?php } ?>
</ul>

3 Answers

Erik McClintock
Erik McClintock
45,783 Points

Azumi,

The instructions could've been a little more explicit here, but the issue is that you are still echoing $flavor1 and $flavor2 inside your foreach loop, when instead, you should be echoing the temporary variable $flavor that your foreach loop has created to hold each value of your array as it loops over them.

<?php foreach ( $flavors as $flavor ) { ?>
    <li><?php echo $flavor; ?></li>
  <?php } ?>

Erik

Hey erik, Ive typed in the code but it still does not work, once i typed it in, it says task 4 no longer passes, can you please check that for me?? please thanks very much

Erik McClintock
Erik McClintock
45,783 Points

Azumi,

Can you copy and paste your new code here so that I can take a look?

Erik

hey erik, my code is this

<?php

    $flavors = array ("Chocolate","Vanilla","Stawberry");

?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors) ?> 
  flavors of ice cream.</p>
<ul>
  <?php foreach ( $flavors as $flavor ) { ?>
    <li><?php echo $flavor; ?></li>
  <?php } ?>
</ul>

then it says task 4 is no longer passing.

Erik McClintock
Erik McClintock
45,783 Points

Azumi,

Which task number are you on now that's failing? The only error I'm seeing in your code is a missing semi-colon at the end of your echo count($flavors) line, but I doubt that's the issue, as I can't imagine you had the semi-colon and then went back and deleted it in a later task.

Erik

Azumi,

I have been developing in PHP for a while and I found the way that question is arranged to be extremely confusing. I got it to pass using the following code:

<?php

    $flavors = ["Chocolate", "Vanilla", "strawberry"];

?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> flavors of ice cream.</p>
<ul> 
<?php
foreach($flavors as $flavor){
    echo "<li>" . $flavor . "</li>";
}
?>
</ul>

Long story short, your code is fine and this is a bug. You should end statements with semi-colons like Erik McClintock said, but the reason that code would not fire is because you have a line break after <?php echo count($flavors);?> and "flavors of ice cream."

Hope this helps.

stephen thank you very much for your clarification for this question! it really got me confused for a while!

thanks so much again! oliver

Thank you, Stephen. I would have been stuck on this step for hours.... It is formatted differently than how the instructor advised to write such code in the video example...