Re: Pull request for array_filter() improvement
Hi Sebastian,
I would be fine with that too, but this might break existing code that uses
internal functions which behave differently when a second argument is
passed.
One might also make the argument that creating an additional ZVAL that's
never used in a callback is a waste of cpu.
I'm not sure about either of those counter arguments, but I added them for
anyone else to pick up :)
On Thu, Feb 21, 2013 at 4:02 PM, Sebastian Krebs <[email protected]>wrote:
>
>
>
> 2013/2/21 Tjerk Anne Meesters <[email protected]>
>
>> 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
>
--
--
Tjerk
Thread (5 messages)