Re: Pull request for array_filter() improvement

From: Date: Thu, 21 Feb 2013 09:57:11 +0000
Subject: Re: Pull request for array_filter() improvement
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-66098@lists.php.net to get a copy of this message
On Thu, Feb 21, 2013 at 5:31 PM, Leigh <leight@gmail.com> wrote: > > On 21 February 2013 07:08, Tjerk Anne Meesters <datibbaw@php.net> 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

« previous php.internals (#66098) next »