note 34793 added to function.each

From: Date: Wed, 06 Aug 2003 23:03:41 +0000
Subject: note 34793 added to function.each
Groups: php.notes 
Request: Send a blank email to php-notes+get-53537@lists.php.net to get a copy of this message
Hi! I just want to know why does everybody use this: while (list ($key, $val) = each ($array)) { ... } instead of this: foreach ($array as $key => $val) { ... } Because i think the latter is much prettier,shorter and easier! P.S. Moreover in the first case you have to reset() the array to make it work "properly" (if you want to go through all elements from the first), but in the second it's done automatically! Sly ---- Manual Page -- http://www.php.net/manual/en/function.each.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34793 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34793&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34793&report=yes

« previous php.notes (#53537) next »