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 Enhancing a Simple PHP Application Adding Search: Controller & View Accounting for Empty Results

Enhancing simple php

i am stuck

index.php
<?php

    $recommendations = array();

?><html>
<body>

    <h1>Flavor Recommendations</h1>

    <ul>
        <?php foreach($recommendations as $flavor) { ?>
      <li><?php if (intval($flavor) => 1) {echo $flavor}; ?></li>
        <?php } ?>
    </ul>

</body>
</html>

1 Answer

Grace Kelly
Grace Kelly
33,990 Points
  1. the task asks for you to include the list tags and the data INSIDE an if statement.

2.the condition is to ask whether or not the $recommendations array is not empty, so you should use the empty() function inside the condition to check that it's not empty, like this:

<?php

 if(!empty($recommendations)) {?> //if the array is NOT empty
  <ul>  //output the list
     <?php  foreach($recommendations as $flavor) { ?> //carry out the foreach loop
            <li><?php echo $flavor; ?></li>
      <?php }?>
       </ul>
   <?php } ?>