Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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 } ?>