Re: Pull request for array_filter() improvement
| From: | Sebastian Krebs | Date: | Thu, 21 Feb 2013 08:02:44 +0000 |
| Subject: | Re: Pull request for array_filter() improvement | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-66091@lists.php.net to get a copy of this message | ||
2013/2/21 Tjerk Anne Meesters <datibbaw@php.net>
> Hi,
>
> I found myself wanting a feature of array_filter() with which I can perform
> filtering based on the array key instead of the value.
>
> To scratch this itch, I decided to dive into C again and just add the
> feature. My proposal is to add a third argument to array_filter() that will
> send the array keys to the callback.
>
Hi,
Why not simply _always_ push the key to the callback?
Regards,
Sebastian
>
> function myfilter($value, $key)
> {
> return $key > 4;
> }
>
> array_filter([1, 2, 3, 4, 5, 6, 7], 'myfilter', true);
> // returns: [6, 7]
>
>
> The pull request can be found here:
> https://github.com/php/php-src/pull/287
>
> If this is useful for the language as a whole, do let me know what else I
> should do to champion it.
>
> Thanks!
>
> --
> --
> Tjerk
>
--
github.com/KingCrunch