Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66092 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67579 invoked from network); 21 Feb 2013 08:08:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2013 08:08:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.50 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.128.50 mail-qe0-f50.google.com Received: from [209.85.128.50] ([209.85.128.50:37877] helo=mail-qe0-f50.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/D9-03224-9E5D5215 for ; Thu, 21 Feb 2013 03:08:09 -0500 Received: by mail-qe0-f50.google.com with SMTP id w7so52514qeb.23 for ; Thu, 21 Feb 2013 00:08:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=P0wbutO8GaPY4fjfX/eIne68/rHmMEhe3b5nxzcFJw8=; b=IH2X2DWxJS+u/QjWNNcbP/B6Pp5pxK75BB6ZGvr4ttqneAwIdhqhAATp1KAjoCJ8LI ZMLBdYPm5OCG08as3CYubLEGbqWaQWqJsEnehxsUXLW+kg7YygFxOPmc3ca7ND+K/nP1 mg8MUhrDtxSPkFF/1TybMItZr+ANMslS09DRwUU4c/Z7y81Bpya6qbhRKYrLuANGr2Xp 4A7lXS0+yA4wsx8wwmo/mB6JP6kPomi9Lf+reJyPhl8IafX9xrHJsRcIAODSR+iMyXT0 5cAVEy5M0AWQ7cfatHo1R+LoJSs6rfmOYt7PpzC6UpB23DIpSO2KHvPK9z5JVrbD3PKG kHIg== MIME-Version: 1.0 X-Received: by 10.224.177.204 with SMTP id bj12mr5227556qab.67.1361434086421; Thu, 21 Feb 2013 00:08:06 -0800 (PST) Sender: tjerk.meesters@gmail.com Received: by 10.49.14.133 with HTTP; Thu, 21 Feb 2013 00:08:06 -0800 (PST) In-Reply-To: References: Date: Thu, 21 Feb 2013 16:08:06 +0800 X-Google-Sender-Auth: lGCqcsupxQ9WaG9HD-75reY1aSQ Message-ID: To: Sebastian Krebs Cc: PHP Internals Content-Type: multipart/alternative; boundary=20cf302ef9401b3e6c04d63793d2 Subject: Re: [PHP-DEV] Pull request for array_filter() improvement From: datibbaw@php.net (Tjerk Anne Meesters) --20cf302ef9401b3e6c04d63793d2 Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > > > > 2013/2/21 Tjerk Anne Meesters > >> 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 --20cf302ef9401b3e6c04d63793d2--