View Full Version : each()

Jon W
01-14-2008, 01:17 AM
Hello everyone!

Just a quick question. I was just wondering if you guys could me a better idea on what the each() does. Give me a idea how this is used and how it comes to use. I understand what it suppose to do kinda, but I just don't get how it can come to use.

Jon W

01-14-2008, 02:00 AM
Each is used as a means to seperate individual values from an array:

$myArr = array ('I', 'AM', 'AN', 'ARRAY');
list ($v1, $v2, $v3, $v4) = each($myArr);

The $v* variables now contain each item of the myArr. Not really useful IMO, its almost like a 'cheap' way of getting around unset variable problems if no corresponding data exists. Strangely enough, it is not a part of the iteration aggregates, and not normally used in object traversal. Kinda odd IMO, it would probably help a lot with object control.

Jon W
01-14-2008, 03:50 AM

Thanks for your reply. It was truely helpful.

Jon W.