Re: [PHP-DEV] array_seek function

2010-04-15 Thread Peter Cowburn
2010/4/15 Derick Rethans : > On Tue, 13 Apr 2010, Felix De Vliegher wrote: > >> Update: http://phpbenelux.eu/array_seek-return.patch.txt >> I've kept the fseek()-style return values (0 when fine, -1 when seek >> fails) >> >>> >> >>> Any reason why you picked that over the (IMO more

Re: [PHP-DEV] array_seek function

2010-04-15 Thread Derick Rethans
On Tue, 13 Apr 2010, Felix De Vliegher wrote: > Update: http://phpbenelux.eu/array_seek-return.patch.txt > I've kept the fseek()-style return values (0 when fine, -1 when seek > fails) > >>> > >>> Any reason why you picked that over the (IMO more logical) true/false > >>> approac

Re: [PHP-DEV] array_seek function

2010-04-13 Thread Felix De Vliegher
On 12-apr-2010, at 10:20, Derick Rethans wrote: > On Mon, 22 Mar 2010, Felix De Vliegher wrote: > >> On 17-mrt-2010, at 19:09, Derick Rethans wrote: >> >>> On Wed, 17 Mar 2010, Felix De Vliegher wrote: >>> On 17-mrt-2010, at 17:52, Derick Rethans wrote: > On Wed, 17 Mar 2010, Fel

Re: [PHP-DEV] array_seek function

2010-04-12 Thread Derick Rethans
On Mon, 22 Mar 2010, Felix De Vliegher wrote: > On 17-mrt-2010, at 19:09, Derick Rethans wrote: > > > On Wed, 17 Mar 2010, Felix De Vliegher wrote: > > > >> On 17-mrt-2010, at 17:52, Derick Rethans wrote: > >> > >>> On Wed, 17 Mar 2010, Felix De Vliegher wrote: > >>> > On 17-mrt-2010, at

Re: [PHP-DEV] array_seek function

2010-03-22 Thread Felix De Vliegher
On 17-mrt-2010, at 19:09, Derick Rethans wrote: > On Wed, 17 Mar 2010, Felix De Vliegher wrote: > >> On 17-mrt-2010, at 17:52, Derick Rethans wrote: >> >>> On Wed, 17 Mar 2010, Felix De Vliegher wrote: >>> On 17-mrt-2010, at 17:27, Frederic Hardy wrote: > > Why not use arrayIterat

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Brian Moon
Update: http://phpbenelux.eu/array_seek-return.patch.txt I've kept the fseek()-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

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Felix De Vliegher
On 17-mrt-2010, at 19:09, Derick Rethans wrote: > On Wed, 17 Mar 2010, Felix De Vliegher wrote: > >> On 17-mrt-2010, at 17:52, Derick Rethans wrote: >> >>> On Wed, 17 Mar 2010, Felix De Vliegher wrote: >>> On 17-mrt-2010, at 17:27, Frederic Hardy wrote: > > Why not use arrayIterat

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Derick Rethans
On Wed, 17 Mar 2010, Felix De Vliegher wrote: > On 17-mrt-2010, at 17:52, Derick Rethans wrote: > > > On Wed, 17 Mar 2010, Felix De Vliegher wrote: > > > >> On 17-mrt-2010, at 17:27, Frederic Hardy wrote: > >>> > >>> Why not use arrayIterator::seek() ? > >> > >> Because the functionality isn't

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Felix De Vliegher
On 17-mrt-2010, at 17:52, Derick Rethans wrote: > On Wed, 17 Mar 2010, Felix De Vliegher wrote: > >> On 17-mrt-2010, at 17:27, Frederic Hardy wrote: >>> >>> Why not use arrayIterator::seek() ? >> >> Because the functionality isn't exactly the same. >> ArrayIterator::seek() only sets the array

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Derick Rethans
On Wed, 17 Mar 2010, Felix De Vliegher wrote: > On 17-mrt-2010, at 17:27, Frederic Hardy wrote: > > > > 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 + have

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Felix De Vliegher
On 17-mrt-2010, at 17:27, Frederic Hardy wrote: > > 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 fu

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Patrick ALLAERT
> 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

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Frederic Hardy
2010/3/16 Felix De Vliegher : 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

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Felix De Vliegher
On 17-mrt-2010, at 17:00, Patrick ALLAERT wrote: > 2010/3/16 Felix De Vliegher : >> 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 (

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Patrick ALLAERT
2010/3/16 Felix De Vliegher : > 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 t

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Daniel Convissor
On Wed, Mar 17, 2010 at 04:07:36PM +0100, Pierre Joye wrote: > > 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

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Derick Rethans
On Wed, 17 Mar 2010, Daniel Convissor wrote: > > $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

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Pierre Joye
On Wed, Mar 17, 2010 at 4:02 PM, Daniel Convissor 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 warning > > Why waste time calling

Re: [PHP-DEV] array_seek function

2010-03-17 Thread Daniel Convissor
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 i

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Felix De Vliegher
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

RE: [PHP-DEV] array_seek function

2010-03-16 Thread Jared Williams
> -Original Message- > From: Felix De Vliegher [mailto:felix.devlieg...@gmail.com] > Sent: 16 March 2010 13:31 > To: PHP internals > Subject: [PHP-DEV] array_seek function > > Hi all > > I recently needed seek functionality in arrays, and couldn't > find it in the regular set of arra

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Brian Moon
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 posi

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Stanislav Malyshev
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 s...@zend.com http://www.zend.com/ (408

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Mikko Koppanen
On Tue, Mar 16, 2010 at 4:22 PM, Derick Rethans wrote: > 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 an

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Derick Rethans
On Tue, 16 Mar 2010, Felix De Vliegher wrote: > On 16-mrt-2010, at 17:07, Derick Rethans wrote: > > > On Tue, 16 Mar 2010, Felix De Vliegher wrote: > > > >> 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

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Felix De Vliegher
On 16-mrt-2010, at 17:07, Derick Rethans wrote: > On Tue, 16 Mar 2010, Felix De Vliegher wrote: > >> 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 arra

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Derick Rethans
On Tue, 16 Mar 2010, Felix De Vliegher wrote: > 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 pointe

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Richard Quadling
On 16 March 2010 13:30, 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

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Felix De Vliegher
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 Index: ext/standard/array.c === --- ext/standa

Re: [PHP-DEV] array_seek function

2010-03-16 Thread Pierre Joye
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:3