note 61703 deleted from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Tue, 28 Apr 2009 13:06:08 +0000 |
| Subject: | note 61703 deleted from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153912@lists.php.net to get a copy of this message | ||
Note Submitter: atroxodisse at gmail dot com
----
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.