Re: [PHP-DEV] [VOTE] array_part()
Gustavo Lopes <glopes <at> nebm.ist.utl.pt>
2012-05-29 08:05:06 GMT
On Tue, 29 May 2012 02:28:05 +0200, Stas Malyshev <smalyshev <at> sugarcrm.com>
> This looks very complicated. It might be that some use cases require
> this level of complexity, but I can't remember a case where I would need
> it. That alone does not disqualify the proposal, but I personally very
> much like having something like array_column() rather than whole array
> slicing engine with it's own declarative language inside. The engine
> might be fine, but I imagine many users would want just something like
> array_column() - so at least it'd be nice to have both.
Independently for whether we want array_column this function does things
that no other function built-in currently does and some that no userland
function can even do:
* Extract slices without side effects (array_slice() has side effects).
* Extract slices based on keys on time proportional to the size of the
slice and not to the size of the array.
* Pick an arbitrary number of elements from an array in any permutation
and traversing the array, in worst case -- if we request an element in the
middle --, only once.
A lot of people seem to think this is too complicated. I think that
objection comes from several places:
* People focusing on the most complex usages of the function. The test
cases have to cover complex usages in order to exercise the implementation
correctly, but that doesn't mean the majority of use cases will be that