Re: [RFC] [DISCUSSION] array_part()

From: Date: Mon, 21 May 2012 21:14:05 +0000
Subject: Re: [RFC] [DISCUSSION] array_part()
References: 1 2 3 4 5 6 7 8 9  Groups: php.internals 
Request: Send a blank email to internals+get-60639@lists.php.net to get a copy of this message
First, I'd like to announce the native implementation is available on github: https://github.com/cataphract/php-src/compare/array_part Please review this feature BEFORE voting starts. Unless something comes up that has to be dealt with until then, I want to start voting on Monday, 28th May. Now my answer to Richard: On Mon, 21 May 2012 21:30:24 +0200, Richard Lynch <ceo@l-i-e.com> wrote:
On Mon, May 14, 2012 9:03 am, Gustavo Lopes wrote:
* array_slice() can preserve keys, array_part() cannot because when collapsing levels this would mean the possibility of overwriting elements.
A predictable LIFO or FIFO for any collapsed keys would be reasonable, and probably not much more work to implement. By LIFO I mean that the last value to be put under a key would "win" I think that would be the most natural.
Such a behavior would be possible and would not be difficult to implement. However, it raises questions that are not easy to answer like: - should it keep the first or the last keys? Or perhaps it could instead collect all the elements under a new array. - should the behavior for numeric keys differ from that of string keys (perhaps in a array_merge way?) Since the path to add this behavior in the future is straightforward (add another optional argument, like in array_slice), not including it causes little damage in terms of future growth. On the other hand, my hope is that limiting the current design decisions to a easy subset may allow this to be merged rapidly. -- Gustavo Lopes

« previous php.internals (#60639) next »