Re: foreach and current()
| From: | Nicolai Scheer | Date: | Mon, 18 Nov 2013 15:57:38 +0000 |
| Subject: | Re: foreach and current() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-70193@lists.php.net to get a copy of this message | ||
Hi!
On Mon, Nov 18, 2013 at 3:40 PM, Alexey Zakhlestin <indeyets@gmail.com>wrote:
> On 18.11.13, 18:14, Nicolai Scheer wrote:
> > Hi all!
> >
> [using current() inside for loop does not work]
> >
> > Does anyone know what the reasoning behind this behavious is?
>
> current() implementation predates foreach and is totally separate. Main
> difference is, that current()'s "pointer" is attached to the array, and
> foreach's pointer is external.
>
> so you can not run several each()/current() loops on array at the same
> time, but you can have any number of nested foreach's iterating over the
> same array independently.
>
> They can't really be combined because of backwards compatibility
>
Ok, thanks for the clarification. Maybe inserting a hint about this into
the documentation should be considered.
Actually I would not use such code in the wild, it was more an educational
question. :)
Greetings
Nico