Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP Build a Simple PHP Application Working With Functions Displaying Only Four Shirts

Luis S
Luis S
3,027 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
3,027 Points

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

Cheers!