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.
Teacher Russell16,872 Points
random fun with arrays
Can someone offer someone offer some explanation of what's happening in this video around 3:00? Too many big changes too quickly and I can't quite figure out why or what:) Thank you!
Jonathan GrieveTreehouse Moderator 89,887 Points
Usually, when you're struggling because it's seemingly happening too fast, it's a good time to watch the video again... you might begin to absorb a little more when you know what to expect in the video.
But I'll try to explain what's going on :)
We're basically iterating through an array with PHP and displaying the results in the browser.
get_item_html() might not seem likee it's doing anything much but we're echoing out the results of a function call.
Every time the loop iterates (which means runs a single cycle through the loop) it will return different items from an array. That's what the 4 does in the rand function. It's limiting the display for 4 random items in the array.
<?php get_item_html($id, $catalog[$id]) ?>