Hi all
I recently needed seek functionality in arrays, and couldn't find it in the regular set of array functions, so I wrote a function for it. (Seek = getting an array value based on the position (or offset, if you want to call it like that), and not the key of the item)
Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warning
I was wondering if it's useful to add this to the family of array functions. I know there is a somewhat similar thing in SPL (ArrayIterator::seek), but that doesn't work exactly like what I was aiming for.
Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn + testcases + docs. Feedback please :-)
Kind regards,
Felix
hi Felix,
Not sure about the usefulness of this function but the name is
misleading (pls reattach the patch as .txt while being at it :). Does
it set the position (_seek) or does it return the value of a given
position (_get_pos)? or both (no idea :)?
Cheers,
Cheers,
On Tue, Mar 16, 2010 at 2:30 PM, Felix De Vliegher
felix.devliegher@gmail.com wrote:
Hi all
I recently needed seek functionality in arrays, and couldn't find it in the regular set of array functions, so I wrote a function for it. (Seek = getting an array value based on the position (or offset, if you want to call it like that), and not the key of the item)
Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningI was wondering if it's useful to add this to the family of array functions. I know there is a somewhat similar thing in SPL (ArrayIterator::seek), but that doesn't work exactly like what I was aiming for.
Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn + testcases + docs. Feedback please :-)
Kind regards,
Felix--
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Hi Pierre
Right now, it returns the value of a given position. In that case, array_get_pos might be a better name. Oh, and I attached the patch with .txt extension :)
Greetings,
Felix
Right now, it returns the value of a given position. In that case,
array_get_pos might be a better name. Oh, and I attached the patch
with .txt extension :)
Does it also seek the array pointer? Because I think array_seek that
moves the pointer, in combination with current()
and key()
might make
slightly more sense?
with kind regards,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Right now, it returns the value of a given position. In that case,
array_get_pos might be a better name. Oh, and I attached the patch
with .txt extension :)Does it also seek the array pointer? Because I think array_seek that
moves the pointer, in combination withcurrent()
andkey()
might make
slightly more sense?
Mikko updated the patch a bit to set the array pointer correctly (and make it perform a bit better when dealing with large arrays), my version left it one position too far. So yes, that's possible. The updated version can be found here: http://valokuva.org/~mikko/array_seek.patch.txt
Cheers,
Felix
Right now, it returns the value of a given position. In that case,
array_get_pos might be a better name. Oh, and I attached the patch
with .txt extension :)Does it also seek the array pointer? Because I think array_seek that
moves the pointer, in combination withcurrent()
andkey()
might make
slightly more sense?Mikko updated the patch a bit to set the array pointer correctly (and
make it perform a bit better when dealing with large arrays), my
version left it one position too far. So yes, that's possible. The
updated version can be found here:
http://valokuva.org/~mikko/array_seek.patch.txt
I was also thinking, can we just make this work just like fseek (with a
"whence" parameter) as well? (http://uk3.php.net/fseek)
with kind regards,
Derick
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
I was also thinking, can we just make this work just like fseek (with a
"whence" parameter) as well? (http://uk3.php.net/fseek)
Hi,
not sure how SEEK_END
is supposed to work with arrays but here is
SEEK_SET
and SEEK_CUR
(with positive and negative offset)
http://valokuva.org/~mikko/array_seek_whence.patch.txt
--
Mikko Koppanen
Hi
As SEEK_END
only makes sense with zero or negative offsets (for arrays anyway), I've come up with an implementation for SEEK_END:
http://phpbenelux.eu/array_seek.patch.txt
So you can do:
$arr = array('a', 'b', 'c', 'd');
echo array_seek($arr, -2, SEEK_END); // outputs 'b'
echo array_seek($arr, 0, SEEK_END); // outputs 'd'
Cheers,
Felix
I was also thinking, can we just make this work just like fseek (with a
"whence" parameter) as well? (http://uk3.php.net/fseek)Hi,
not sure how
SEEK_END
is supposed to work with arrays but here is
SEEK_SET
andSEEK_CUR
(with positive and negative offset)
http://valokuva.org/~mikko/array_seek_whence.patch.txt--
Mikko Koppanen
Hi!
Right now, it returns the value of a given position.
How it's different from:
array_slice()
returns the sequence of elements from the array array as
specified by the offset and length parameters?
Stanislav Malyshev, Zend Software Architect
stas@zend.com http://www.zend.com/
(408)253-8829 MSN: stas@zend.com
Right now, it returns the value of a given position.
How it's different from:
array_slice()
returns the sequence of elements from the array array as
specified by the offset and length parameters?
array_slice returns an array of elements. This function would return the
value at the given position.
Brian.
Hi all
I recently needed seek functionality in arrays, and couldn't find it in the regular set of array functions, so I wrote a function for it. (Seek = getting an array value based on the position (or offset, if you want to call it like that), and not the key of the item)
Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningI was wondering if it's useful to add this to the family of array functions. I know there is a somewhat similar thing in SPL (ArrayIterator::seek), but that doesn't work exactly like what I was aiming for.
Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn + testcases + docs. Feedback please :-)
Kind regards,
Felix--
Maybe not as efficient as it could be but ...
<?php
$input = array('One' => 'Itchy', 'Two' => 'Knee', 'Three' => 'San',
'Four' => 'She');
echo @reset(array_keys(array_values($input), 'Knee'));
Richard.
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
EE4Free : http://www.experts-exchange.com/becomeAnExpert.jsp
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling
Felix De Vliegher wrote:
Hi all
I recently needed seek functionality in arrays, and couldn't find it
in the regular set of array functions, so I wrote a function for it.
Seek = getting an array value based on the position (or offset, if you
want to call it like that), and not the key of the item)Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warning
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.
My 2 cents,
- Chris
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
On Tue, Mar 16, 2010 at 2:12 PM, Christian Schneider
cschneid@cschneid.com wroteI 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.
slightly modified version of the original patch
http://valokuva.org/~mikko/array_seek.patch.txt. The difference to the
I once porpoised similar patch to in_array, where it didn't reset the
position after finding the "found element".
In applications like PhD, this is extremely useful and safes us at
least 10% overhead (at the time I benchmarked it with my patch to
in_array()
).
I think we wound up with something like:
while (list($key, $val) = each($array)) {
if ($key == "foobar") {
break;
}
}
next($array);
$current_index = current($array);
To get the next value after the known "currently known value (or key)".
In an application like PhD (which already brought 24hours (DSSSL
24hours, xsltproc two formats compile time to) down to ~3-4minutes
(3-5formats), 10% of language overhead is extremely important, so I
am all for a function that can do this (our/my goal is max 1minute...
- sorry, HD read/write is still extremely expensive :(, it simply cant
get faster then that afaict - if you have an idea; GSOC is open for
experiments.. :D).
-Hannes
-----Original Message-----
From: Felix De Vliegher [mailto:felix.devliegher@gmail.com]
Sent: 16 March 2010 13:31
To: PHP internals
Subject: [PHP-DEV] array_seek functionHi all
I recently needed seek functionality in arrays, and couldn't
find it in the regular set of array functions, so I wrote a
function for it. (Seek = getting an array value based on the
position (or offset, if you want to call it like that), and
not the key of the item)Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3 echo
array_seek($input, 5); // returns NULL, emits an out of range
warning
Remember doing something like this in the past...
$input = array(3, 'bar', 'baz');
$iterator = new ArrayIterator($input);
$iterator->seek(2);
echo $iterator->current();
$iterator->seek(0);
echo $iterator->current();
$iterator->seek(5); // throws OutOfBoundsException
Though a specific function does make sense, imo.
Jared
Hi:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warning
Why waste time calling a function when this can be done right now by
acting on the array itself?
$input = array(3, 'bar', 'baz');
echo $input[2]; // returns 'baz'
echo $input[0]; // returns 3
echo $input[5]; // returns NULL, Notice: Undefined offset: 5
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
On Wed, Mar 17, 2010 at 4:02 PM, Daniel Convissor
danielc@analysisandsolutions.com wrote:
Hi:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningWhy waste time calling a function when this can be done right now by
acting on the array itself?
Please double check what the patch does, test it, and think again
about this question (hint: pos != key) :)
Cheers,
$input = array(3, 'bar', 'baz');
echo $input[2]; // returns 'baz'
echo $input[0]; // returns 3
echo $input[5]; // returns NULL, Notice: Undefined offset: 5--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409--
--
Pierre
@pierrejoye | http://blog.thepimp.net | http://www.libgd.org
Please double check what the patch does, test it, and think again
about this question (hint: pos != key) :)
And once again, skimming emails (can you say ADD? I knew you could.)
bites me in the tush. :) I just looked at the first sentence and the
code. Missed the second sentence.
Thanks,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
data intensive web and database programming
http://www.AnalysisAndSolutions.com/
4015 7th Ave #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningWhy waste time calling a function when this can be done right now by
acting on the array itself?
Because array keys can be sparse and don't have to be "in order".
regards,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
2010/3/16 Felix De Vliegher felix.devliegher@gmail.com:
Hi all
I recently needed seek functionality in arrays, and couldn't find it in the regular set of array functions, so I wrote a function for it. (Seek = getting an array value based on the position (or offset, if you want to call it like that), and not the key of the item)
Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningI was wondering if it's useful to add this to the family of array functions. I know there is a somewhat similar thing in SPL (ArrayIterator::seek), but that doesn't work exactly like what I was aiming for.
Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn + testcases + docs. Feedback please :-)
Kind regards,
Felix
Hi Felix,
What about adding a new int parameter to PHP array function: next()
and prev()
instead of adding a new one?
Cheers,
Patrick
2010/3/16 Felix De Vliegher felix.devliegher@gmail.com:
Hi all
I recently needed seek functionality in arrays, and couldn't find it in the regular set of array functions, so I wrote a function for it. (Seek = getting an array value based on the position (or offset, if you want to call it like that), and not the key of the item)
Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningI was wondering if it's useful to add this to the family of array functions. I know there is a somewhat similar thing in SPL (ArrayIterator::seek), but that doesn't work exactly like what I was aiming for.
Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn + testcases + docs. Feedback please :-)
Kind regards,
FelixHi Felix,
What about adding a new int parameter to PHP array function:
next()
andprev()
instead of adding a new one?
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.
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).
Cheers,
Felix
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
2010/3/16 Felix De Vliegher felix.devliegher@gmail.com:
Hi all
I recently needed seek functionality in arrays, and couldn't find it in the regular set of array functions, so I wrote a function for it. (Seek = getting an array value based on the position (or offset, if you want to call it like that), and not the key of the item)
Basically you can use it like this:
$input = array(3, 'bar', 'baz');
echo array_seek($input, 2); // returns 'baz'
echo array_seek($input, 0); // returns 3
echo array_seek($input, 5); // returns NULL, emits an out of range warningI was wondering if it's useful to add this to the family of array functions. I know there is a somewhat similar thing in SPL (ArrayIterator::seek), but that doesn't work exactly like what I was aiming for.
Attached is a patch for the function against the 5.3 branch. If approved, I could add it to svn + testcases + docs. Feedback please :-)
Kind regards,
Felix
Hello Felix !
Why not use arrayIterator::seek() ?
Best regards,
Fred
Hello Felix !
Why not use arrayIterator::seek() ?
Best regards,
Fred
Because the functionality isn't exactly the same. ArrayIterator::seek() only sets the array pointer, array_seek would also return the value + have fseek()
-like functionality with the SEEK_* consts and optional negative offsets.
Felix
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.
To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key with key()
and current()
.
with kind regards,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key withkey()
andcurrent()
.
Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept the fseek()
-style return values (0 when fine, -1 when seek fails)
Cheers,
Felix
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key withkey()
andcurrent()
.Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)
Any reason why you picked that over the (IMO more logical) true/false
approach?
with kind regards,
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key withkey()
andcurrent()
.Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?
No, just to keep it similar to fseek()
. Either way works for me.
Felix
Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?No, just to keep it similar to
fseek()
. Either way works for me.
I would expect it to return the same as current, next, prev rather than
a file io function.
Brian.
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key withkey()
andcurrent()
.Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?
No, it makes more sense to use the boolean return values, I was just using your fseek()
analogy. Although I still find it useful to return the seeked value, and false when seek fails (basically how next()
, reset()
and friends behave).
Johannes: If we decide on the details, if this something I could commit in 5.3 or do you rather want me to wait until 5.4?
Cheers,
Felix
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key withkey()
andcurrent()
.Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?No, it makes more sense to use the boolean return values, I was just
using yourfseek()
analogy. Although I still find it useful to return
the seeked value, and false when seek fails (basically hownext()
,
reset()
and friends behave).
Has this been added to trunk now? Or not yet?
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
Why not use arrayIterator::seek() ?
Because the functionality isn't exactly the same.
ArrayIterator::seek() only sets the array pointer, array_seek would
also return the value + havefseek()
-like functionality with the
SEEK_* consts and optional negative offsets.To be honest, I'd rather have the proposed array_seek() return a status
whether the seek worked or not. Notices are uncool and you can already
retrieve data/key withkey()
andcurrent()
.Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?No, it makes more sense to use the boolean return values, I was just
using yourfseek()
analogy. Although I still find it useful to return
the seeked value, and false when seek fails (basically hownext()
,
reset()
and friends behave).Has this been added to trunk now? Or not yet?
No, still have it lying around. Can I commit this?
Cheers,
Felix
Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?No, it makes more sense to use the boolean return values, I was just
using yourfseek()
analogy. Although I still find it useful to return
the seeked value, and false when seek fails (basically hownext()
,
reset()
and friends behave).Has this been added to trunk now? Or not yet?
No, still have it lying around. Can I commit this?
Dunno... did you go with true/false in the end, or returning the value?
I just realize that in the latter case you wouldn't be able to see
whether the seek actually worked, because every value could be a
"correct" value. I'd prefer the true/false thing still because of that.
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug
2010/4/15 Derick Rethans derick@php.net:
Update: http://phpbenelux.eu/array_seek-return.patch.txt
I've kept thefseek()
-style return values (0 when fine, -1 when seek fails)Any reason why you picked that over the (IMO more logical) true/false
approach?No, it makes more sense to use the boolean return values, I was just
using yourfseek()
analogy. Although I still find it useful to return
the seeked value, and false when seek fails (basically hownext()
,
reset()
and friends behave).Has this been added to trunk now? Or not yet?
No, still have it lying around. Can I commit this?
Dunno... did you go with true/false in the end, or returning the value?
I just realize that in the latter case you wouldn't be able to see
whether the seek actually worked, because every value could be a
"correct" value. I'd prefer the true/false thing still because of that.
I realise that I'm late to the game here but do have a couple of thoughts.
- The function name: this will go hand-in-hand with functions like
current()
,next()
,prev()
,key()
,reset()
rather than the other
array_* functions... wouldn't "seek" be more appropriate given its
siblings? - The return value: the purpose of the function is to seek, not to get
what is at the seeked-to position (right?) so true/false (+ warning?)
makes most sense to me.
Derick
--
http://derickrethans.nl | http://xdebug.org
Like Xdebug? Consider a donation: http://xdebug.org/donate.php
twitter: @derickr and @xdebug