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 Enhancing a Simple PHP Application Refactoring the Codebase Separating Concerns: Views

Nick Davies
Nick Davies
7,972 Points

Get_products_recent isn't working functionally.

I have been working through the enhancing a simple PHP application via my own website. and when I updated the code with the following it only shows the 1 image:

my get_images_all array has 10 items in it.

function get_images_recent(){ $recent = array(); $all = get_images_all();

$total_imgs = count($all); $position = 0;

foreach ($all as $image) { $position = $position + 1; if ($total_imgs - $position > 10) { $recent[] = $image; } return $recent; } }

It doesn't bring back an error. Please could you help me by explaining to me why only the one is showing?

1 Answer

Hi Nick,

Your code seem to have the capability of displaying recent_images_all only when you have images that are greater that 11 in the $all array.

To display all images from $all array you will have to change the condition.

e.g. if your $all array has 13 images, the first two images in the array will be displayed.

For a better help, describe what exactly what you want to achieve withe code.

Happy coding.