note 61703 added to control-structures.foreach
| From: | atroxodisse at gmail dot com | Date: | Fri, 10 Feb 2006 01:04:46 +0000 |
| Subject: | note 61703 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-103395@lists.php.net to get a copy of this message | ||
I just noticed something. I created an array, Looped through a mysql result with a while and added
values to that array with an index that I incremented manually, starting at position 1. After
closing the while loop I added an element at position 0 of the array. When I looped through that
array with a foreach loop it evaluated the elements starting from the first element that was added
instead of starting at position 0. I'm not sure if that was intentional but it does not seem
to be in the documentation. So in this case looping through the array with a foreach was not the
same as looping through it with a for loop like this:
for($i =0; $i<count($myarray); $i++)
To anyone coming from a C or C++ background this might be confusing.
----
Server IP: 64.71.164.2
Probable Submitter: 69.230.47.58
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+61703
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+61703&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+61703&report=yes
Search -- http://master.php.net/manage/user-notes.php