Re: PR 287 - added use_keys argument to array_filter() [Discussion]

From: Date: Tue, 18 Jun 2013 22:08:22 +0000
Subject: Re: PR 287 - added use_keys argument to array_filter() [Discussion]
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 18 June 2013 18:24, Sherif Ramadan <[email protected]> wrote:

> > Nevertheless, I'd say go with a new array_filter_key() function, because
> > that permits using existing one-parameter functions like that strlen as a
> > callback, instead of forcing two-parameter callback functions.
> >
> The current patch does not force the callback to take two arguments. By
> default the existing behavior is maintained since the third argument is
> false by default. I still don't hear a good argument for adding a new
> function.


I'm very much on the "new function" side of the fence. Basic (one-word)
arguments for this include familiarity and simplicity. Familiarity, since
we're used to *_key functions for arrays. It will come as absolutely no
surprise to see the _key function spring up out of nowhere and its use is
blindingly obvious for anyone who has ever used array_filter(). Simplicity
since, err.. what were those flags again? is it $key first or $value? is
there an ARRAY_FILTER_BOTH? Also, I don't pretend my time with PHP covers
everything that everyone has ever done or wanted to do, but I cannot think
of a time when I wanted to filter an array on both the key *and* the value
at the same time: of course, it's easy to make up use cases.


Thread (39 messages)

« previous php.internals (#67729) next »