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 PHP Arrays and Control Structures PHP Loops Todo App

emanelbaradei
emanelbaradei
11,395 Points

$item vs $key vs $value vs $id ? Any one can help please define the difference? Im very confused...

In the video of Todo app of LOOPS in PHP Arrays and Control Structures course, i watched the video several times and im getting there to understand it (i know! :'O ) But what is really driving me crazy is that im not sure when to use $item or $key or $value or $id... Anyone can explain or explain the difference if there is any... , please?

Andrew Patella
Andrew Patella
2,270 Points

Hello! I am not quite sure I understand your question correctly, but those are all variables that are being used in the loops and conditionals. The $key => $item is being assigned the key and value from your array as your foreach loop goes around. I suggest going back and re-watching the videos on conditionals and also associative arrays. let me know if that helps

2 Answers

Andrew Patella
Andrew Patella
2,270 Points

I totally understand! there is a lot of data in a short amount of time. I have the same problems! Im glad you figured it out :)

emanelbaradei
emanelbaradei
11,395 Points

Thanks Andrew Patella, i was just very confused from the video to process all the info.. for some reason my mind didn't get they were all just variables and so all the video was confusing, i re watched several times and read the documentation about it which made it clearer and your explanation confirmed what i understood eventually so really Thanks!

facepalm

I just had the same Issue. Who could have known, that a variable is alloud to have different names ;)