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 trialLuis S
5,407 PointsIsn't better to echo the last items on the array like this?
<?php
function lastItems($array, $items) {
for ( $x = 0; $x < $items ; $x++ ) { //the last "$items" shirts
//decrementing index of array and echoing value
echo $array[(count($array)-1)-$x];
}
$shirts = array("red","green","blue","black");
lastItems($shirts, 3); //call lastItems to output last 3 items
?>
1 Answer
Luis S
5,407 PointsThank you ....I ll check how to post code correctly ...thanks for fixing my first attempt....
Cheers!
Robert Richey
Courses Plus Student 16,352 PointsRobert Richey
Courses Plus Student 16,352 PointsHi Luis,
I added markdown to help make the code more readable. If you're curious about how to add markdown like this on your own, checkout this thread on posting code to the forum . Also, there is a link at the bottom called Markdown Cheatsheet that gives a brief overview of how to add markdown to your posts.
Cheers!