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 Working With Functions Displaying Only Four Shirts

Luis S
Luis S
5,451 Points

Isn'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

?>

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

1 Answer

Luis S
Luis S
5,451 Points

Thank you ....I ll check how to post code correctly ...thanks for fixing my first attempt....

Cheers!