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

Geoff Bowen
Geoff Bowen
1,877 Points

She skips over this too fast...

https://teamtreehouse.com/library/build-a-basic-php-website/listing-and-sorting-inventory-items/displaying-categories

I find her to be a bit too quick, perhaps at typing - making it hard to follow at times. Given the comments I'm not the only one.

There is a bit where she does the line:

foreach ($catalog as $id => $item) { .. }

She doesn't explain what this is doing at all, and I cannot find any previous guidance on this. I believe, from Google, that this line is returns the key for the array item, rather than the default which is value. But I don't get how it doing that? Why does she not explain, or what previous lesson is this explained in so I can check it out?

Geoff Bowen
Geoff Bowen
1,877 Points

Ah-ha there is almost an identical question to this, where they wonder why she doesn't refer to $id as $key in this particular line. If she had done that, it would be clearer to understand - e.g. within the array $catalog she wants to refer to the key as $key and the value of that array item as $item. I wonder why she made used $id instead of $key in this example?