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 trialammarkhan
Front End Web Development Techdegree Student 21,661 PointsWhy 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?
ammarkhan
Front End Web Development Techdegree Student 21,661 PointsEric 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.
ammarkhan
Front End Web Development Techdegree Student 21,661 PointsJames 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
13,220 PointsThe $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
16,383 Pointsyoure not alone. she is not explaining well.
Leigh Maher
21,830 PointsAgreed. 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.
ilanaguttman
2,700 PointsRight. 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.
Eric Stermer
9,499 PointsEric Stermer
9,499 Pointsyou 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?