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

I Can't See, There Are No Previews In This PHP Challenge.

Challenge task 5 of 7

Right now, the unordered list does not show the flavors from our array. In the next few tasks, we'll change that. This task has two steps. (1) Add the start of a foreach loop with an opening curly brace after the opening <ul> tag but before the first opening <li> tag. The foreach loop should load each element from the flavors array, one at a time, into another variable named flavor. (2) Add the closing curly brace for the foreach loop after the final closing </li> but before the closing </ul>.

<?php

  $flavors = array("Chocolate" , "Vanilla" , "Butter Pecan");


?>
<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 $flavor;
    <li><?php echo $flavor1; ?></li>
    <li><?php echo $flavor2; ?></li>
} ?>
</ul>

9 Answers

Hi CRYSTAL,

I'm not sure a preview would help much here. Mixing php and html can get confusing but after a little while you will get the hang of it, hang in there. There are also different was you can mix them and after a little practice you will begin to understand. One of the things to keep in mind is that one of the things php was designed for is to generate html.

Jeff

<?php
$flavors = array("Chocolate", "Vanilla", "Black Cherry", "Cookie Dough");

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

Hi Jeff I Wanted To Take flavor1 And Flavor2 Off, Bur Didn'r Want To Mess Up...LOL

Didn't want to mess up? That's what I'm best at. The people who make me laugh are the ones who are POSITIVE their code is correct. Ya maybe, but in the coding biz 9 times out of 10 it's operator error.

LOL...Thanks Big Daddy, I Needed To Laugh. :-)

There Is One More Thing, Like Right Here (Check This Out).

Associative keys - The Key Points To The Value (This Is What I Heard)

(How Is This Wrong???)

Challenge task 2 of 7

Add an element to that array with a key of "title" and a value of "The Empire Strikes Back".

<?php $movie = array(); 
"title" => "The Empire Strikes Back";
?>

You're close, check it out. It's in the parenthesis.

<?php

$movie = array(
"title" => "The Empire Strikes Back"
);

?>

WOW!!! His Responses Were Outside Of The Braces.

Thanks Again, Gonna Crash. Have An Awesome Evening Jeff, You Have Definitely Made My Night. :-)

What did you mean by "WOW!!! His Responses Were Outside Of The Braces."

Crystal, it's late, I'm tired, and the challenge does get confusing. Here is the rest of the code. Study it or you won't be doing what you want with your website.

<?php
$movie = array(
    "title" => "The Empire Strikes Back",
  "year" => 1980,
  "director" => "Irvin Kershner",
  "imdb_rating" => 8.8,
  "imdb_ranking" => 11
);
?>

<h1><?php echo $movie["title"]; ?> (<?php echo $movie["year"]; ?>)</h1>

<table>
  <tr>
    <th>Director</th>
    <td><?php echo $movie["director"]; ?></td>
  </tr>
  <tr>
    <th>IMDB Rating</th>
    <td><?php echo $movie["imdb_rating"]; ?></td>
  </tr>
  <tr>
    <th>IMDB Ranking</th>
    <td><?php echo $movie["imdb_ranking"]; ?></td>
  </tr>
</table>

Thank You

Thank You So Much, The Website Is Looking Better. :-)

http://maggiewincher.com/