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

Manipulating an Array 1/1

I don't see what i'm doing wrong can somebody please help me.

The main part of the question is : "The owner of the ice cream shop would like this order changed so that the flavors are displayed in descending order instead, starting with Cookie Dough first and Jalapeno So Spicy last. Leave the $flavors array itself in the same order, but modify something else in this code block to achieve that."

This is my code:

<?php

$flavors = array(
    "Jalapeno So Spicy",
    "Avocado Chocolate",
    "Peppermint",
    "Vanilla",
    "Cake Batter",
    "Cookie Dough"
);

$flavors_r = array_reverse($flavors);
echo $flavors_r;

?>

I don't see why it's not working

If I do a var_dump($flavors_r) it shows it in the right order but with a bunch of extra stuff.

1 Answer

Hi Michael, Please check this code and see if it works.

<html> <body> <?php

$flavors = array( "Jalapeno So Spicy", "Avocado Chocolate", "Peppermint", "Vanilla", "Cake Batter", "Cookie Dough" );

$flavors_reverse = array_reverse($flavors);

?> <ul> <?php

$list_html = "";
foreach($flavors_reverse as $flavor) {
    $list_html = $list_html . "<li>";
    $list_html = $list_html . $flavor;
    $list_html = $list_html . "</li>";
}
echo $list_html;

?> </ul> </body> </html>

it worked :T

I feel stupid now I completely disregarded the rest of the code on the bottom. Thanks alot !