Re: array_seek function

From: Date: Wed, 17 Mar 2010 16:30:05 +0000
Subject: Re: array_seek function
References: 1 2 3  Groups: php.internals 
Request: Send a blank email to internals+get-47372@lists.php.net to get a copy of this message
> Hi Patrick
>
> That's of course possible, but that would only allow seeking to a relative position to
> where the array pointer is at that moment. The functionality also gets a bit ambiguous by adding an
> optional parameter. You're not going to the next or prev position of the array anymore.

You could always use reset() in combination with next($int). The main
benefit I see doing so is that you can do something like:

reset($array);
$jump = 3;
while ($elem = next($jump)) {
    // Some treatment that needs to be done on every $jump element
}

Which would be slower and less readable with array_seek() of course,
depends on your use case!

> And I think functions like next, prev, current etc should be kept easy to use. If you want
> seek-like functionality, use the designated array function for that (if this one should make it into
> php, that is).

Well, it wouldn't be a mandatory option of course for BC. It would
jump forward/backward X elements just where X is 1 by default. It
could make sense to have both maybe?

Let's wait other's opinion.

Cheers,
Patrick


Thread (34 messages)

« previous php.internals (#47372) next »