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

aaron durber
13,400 Pointscode challenge manipulating an array
Hi
i am having problems with this question. my code is
<?php
$flavors = array( "Jalapeno So Spicy", "Avocado Chocolate", "Peppermint", "Vanilla", "Cake Batter", "Cookie Dough" );
?> <?php $list_html = array_reverse($flavors); foreach($flavors as $flavor) { $list_html = $list_html . ""; $list_html = $list_html . $flavor; $list_html = $list_html . ""; } echo $list_html;
?>
it will display the list but the code test fails me. Could anyone help please
many thanks
4 Answers

Michael Nguyen
6,138 PointsCan you repost your code with correct formatting using how-to-type-code-in-the-forum and post the question ?

aaron durber
13,400 Pointslike so? <html> <body> <?php $flavors = array( "Jalapeno So Spicy", "Avocado Chocolate", "Peppermint", "Vanilla", "Cake Batter", "Cookie Dough" ); ?>
<?php $list_html = array_reverse($flavors); foreach($flavors as $flavor) { $list_html = $list_html . ""; $list_html = $list_html . $flavor; $list_html = $list_html . ""; } echo $list_html; ?> </body> </html>
thanks

Michael Nguyen
6,138 PointsCode Wrap your code with 3 backticks (```) on the line before and after. If you specify the language after the first set of backticks, that'll help us with syntax highlighting.
```html
<p>This is code!</p>
```
Also, can you repost the actual question you are trying to do ? I cant help if I dont know what is being asked.

aaron durber
13,400 PointsHi
i am having problems with this question. my code is
<?php
$flavors = array( "Jalapeno So Spicy", "Avocado Chocolate", "Peppermint", "Vanilla", "Cake Batter", "Cookie Dough" );
?> <?php $list_html = array_reverse($flavors); foreach($flavors as $flavor) { $list_html = $list_html . ""; $list_html = $list_html . $flavor; $list_html = $list_html . ""; } echo $list_html;
?>
it will display the list but the code test fails me. Could anyone help please
many thanks

Stefan Ihle
21,013 PointsThe Code should looks like this:
<html>
<body>
```php
<?php
$flavors = array(
"Jalapeno So Spicy",
"Avocado Chocolate",
"Peppermint",
"Vanilla",
"Cake Batter",
"Cookie Dough"
);
$flavors_reversed = array_reverse($flavors);
?>
<ul>
<?php
$list_html = "";
foreach($flavors_reversed as $flavor) {
$list_html = $list_html . "<li>";
$list_html = $list_html . $flavor;
$list_html = $list_html . "</li>";
}
echo $list_html;
?>
</ul> </body> </html>
Like in the video before, you have to assign the array_reverse() method into a new variable like $flavors_reversed or something like that.
The second step is to replace the first variable from the foreach loop to a variable with the same identifier defined above.
The variable $list_html over the foreach loop is an empty variable and it's used for concatenation within the foreach loop.