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

Alejandra Quezada
Alejandra Quezada
3,896 Points

Have you had trouble with loading correctly a challenge?

I'm having trouble with the challenge task 4 of 7 of "listing inventory items":

The paragraph in the HTML displays the number of flavors the store sells, but right now it always shows 2. Change the echo command in that paragraph to display the number of elements in the array.

It keeps showing an error and I can't even preview the result.

Has it happened to you?

Stone Preston
Stone Preston
42,016 Points

can you post the code you are using?

4 Answers

Charlie O'Shea
Charlie O'Shea
18,737 Points

None of the steps of this challenge would show in preview for me either, but previous challenges in this course did work with preview. It'd be great if this could be fixed for future users.

<?php

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

?>
<p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count($flavors); ?> flavors of ice cream.</p>
<ul>
    <li><?php echo $flavor1; ?></li>
    <li><?php echo $flavor2; ?></li>
</ul>
Alejandra Quezada
Alejandra Quezada
3,896 Points

Thanks Preston,

I'm not having trouble with the code. I just mean I couldn't preview anything and don't know if that happens sometimes. The code was:

<?php

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

?> <p>Welcome to Ye Olde Ice Cream Shoppe. We sell <?php echo count ($flavors); ?> flavors of ice cream.</p>

Stone Preston
Stone Preston
42,016 Points

ah I see. Im not sure if any of the PHP code challenges are meant to be previewed or not. I just tried it and it didnt work for me either

Alejandra Quezada
Alejandra Quezada
3,896 Points

Ok, as far as I've experienced, they are... Thanks for the feedback