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 Basic PHP Website (2018) Listing and Sorting Inventory Items Displaying Categories

Why is function so hard to understand

I am trying to wrap my head around the video, i get that we need to check if the current category matches the string in get variable, to display the result but the function used like php array_categories and php array_rand are totally out of my mind, i tried reviewing this video for 3-4 times but failed. Can anyone break it down for me?

Eric Stermer
Eric Stermer
9,499 Points

you need to explain more what you are not understanding. It sounds like you know what the purpose is, but what about the functions are you not getting? The return, why this function, what is the function doing?

Eric Stermer So i didn't get the part where it says $output[] = $id ; i understand that $output[] means append the result array at the end of the array called $output but what is happening here as a result.

James Anwyl Can you pls explain the function is the video, i am totally confused over php $category['id'] and how php $id in $output[] is helping to display the items.

2 Answers

Juan Ferr
Juan Ferr
13,220 Points

The $output is returning an array of ids of products, eg: [104,105,201].....then when that function gets called from catalogue.php it stores that array of ids in a variable called $categories, which is used for a foreach loop, and each id( called $id in the foreach loop) is passed to the function that render a particular element to html using that id.........is that a little more clear?....

Markus Mรถnch
Markus Mรถnch
16,383 Points

youre not alone. she is not explaining well.

Leigh Maher
Leigh Maher
21,830 Points

Agreed. I've noticed in the last few videos that Alena seems to gloss over pretty complex ideas (at least for beginners). She seems to write out the code, and not break it apart and explain the different parts.

Right. She just goes "so then we put this code in here"? WHY? Why are you choosing these specific things to type. We need a diagram or something.