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