Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66098 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81594 invoked from network); 21 Feb 2013 09:57:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Feb 2013 09:57:16 -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.216.177 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.216.177 mail-qc0-f177.google.com Received: from [209.85.216.177] ([209.85.216.177:39684] helo=mail-qc0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 92/6C-03224-A7FE5215 for ; Thu, 21 Feb 2013 04:57:15 -0500 Received: by mail-qc0-f177.google.com with SMTP id u28so3477844qcs.36 for ; Thu, 21 Feb 2013 01:57:11 -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=dopwDgKPMNgPMya2BymWEvXL5j+1zpLx+q0+x7wNCho=; b=r50fcGF7agpBGF8k0ltYV37XnLrJn0c0WJJgMe7weq2HdIjSZsgWzICauwuHJQZooF YusN7KEq4bN47ZpeR8u1PPKMJ778ioB44NbMeUbLZ6dfBeky9TfklimS33Q9NDWckyJz hSBrqYLe81BSHNG1qJOC/nYTuzuyOsR88MixAV6cFPn9eMPCy3UU0m7+Z4PqGItxt6mq RelVjU8z25DYzNW6K3WTrmVRwl87zWLNibLOCESIvtODiG6ntseBSgvkYOrsUdYzPIa6 6pSAojtZWlIuYbd8MUSFr3adgU+/VPcXqdrj67NFJdTftRtv4DoOT5mIUTOEbi9Yrf7V F7RQ== MIME-Version: 1.0 X-Received: by 10.224.185.141 with SMTP id co13mr10949236qab.33.1361440631236; Thu, 21 Feb 2013 01:57:11 -0800 (PST) Sender: tjerk.meesters@gmail.com Received: by 10.49.14.133 with HTTP; Thu, 21 Feb 2013 01:57:11 -0800 (PST) In-Reply-To: References: Date: Thu, 21 Feb 2013 17:57:11 +0800 X-Google-Sender-Auth: PAF4p4sCD1fhfxjXpAWHqUEMbYo Message-ID: To: Leigh Cc: PHP Internals Content-Type: multipart/alternative; boundary=485b397dd78d3533e004d6391955 Subject: Re: [PHP-DEV] Pull request for array_filter() improvement From: datibbaw@php.net (Tjerk Anne Meesters) --485b397dd78d3533e004d6391955 Content-Type: text/plain; charset=ISO-8859-1 On Thu, Feb 21, 2013 at 5:31 PM, Leigh wrote: > > On 21 February 2013 07:08, Tjerk Anne Meesters wrote: > >> 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. >> >> > With the operative word here being *instead*, keeping in line with the > numerous other array functions, would a new function called > array_filter_key() with the same signature as array_filter() be more or > less appropriate? > My use-case is as follows. Imagine you have this array: ["ns.oauth" => " http://specs.openid.net/extensions/oauth/1.0", "ns.alias3" => " http://openid.net/srv/ax/1.0", "oauth.consumer" => "xxx", ...] It's basically a bag of openid parameters. Now I'm tasked to find which alias belongs to "http://specs.openid.net/extensions/oauth/1.0". For this I need two pieces of information: 1. I need to match the value for the namespace 2. I need to make sure only keys that start with "ns." are chosen Currently I use array_keys() to find the keys whose values match the namespace and then iterate over the results to find a key that matches the second requirement. > > The callback still being a single parameter function that receives the key > *instead* of the value. > > Is there a big use case for having the key and value both passed to the > callback at the same time? (I can't think of anything off the top of my > head, but I'm sure someone would use it) > -- -- Tjerk --485b397dd78d3533e004d6391955--