Re: Re: array_seek function

From: Date: Tue, 16 Mar 2010 16:12:15 +0000
Subject: Re: Re: array_seek function
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-47314@lists.php.net to get a copy of this message
On Tue, Mar 16, 2010 at 2:12 PM, Christian Schneider
<cschneid@cschneid.com> wrote
> I thinks the user space implementation
>
> function array_seek($array, $pos)
> {
>        $a = array_values($array);
>        return $a[$pos];
> }
>
> is simple enough to not add a native function for this.
>
> It might not be the most efficient way to do it but I doubt that it is
> something done frequently enough to justify another native function.

Hi,

slightly modified version of the original patch
http://valokuva.org/~mikko/array_seek.patch.txt.
The difference to the
original is that the iterator position is left where the user seeked
to. So something like following should work:

<?php
$arr = array("the", "brown", "fox", "and", "so",
"on");

echo array_seek($arr, 1) . "\n"; // brown
echo next($arr) . "\n"; // fox
?>

Not sure how useful it is to have this in core but I do remember for
looking for a seek function for arrays before.

-- 
Mikko Koppanen


Thread (34 messages)

« previous php.internals (#47314) next »