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 trialAdam Zuckerberg
22,248 PointsChallenge question: get_products_all or $products
Can you count($products) instead of count(get_products_all())?
I am confused why you count the function get_products_all() and you don't simply count the array called $products....How can you count a function?
1 Answer
Jason Anello
Courses Plus Student 94,610 PointsHi Adam,
The $products
array is created inside the get_products_all
function and so it doesn't exist outside of that function.
When you use count(get_products_all());
the get_products_all
function is called which returns an array that contains all the products. That array is then passed into the count
function. So you're not counting the function but instead counting the return value of the function.