Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:64909 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11065 invoked from network); 12 Jan 2013 20:36:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Jan 2013 20:36:30 -0000 Authentication-Results: pb1.pair.com header.from=petercowburn@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=petercowburn@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.219.42 as permitted sender) X-PHP-List-Original-Sender: petercowburn@gmail.com X-Host-Fingerprint: 209.85.219.42 mail-oa0-f42.google.com Received: from [209.85.219.42] ([209.85.219.42:42678] helo=mail-oa0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/81-24230-D49C1F05 for ; Sat, 12 Jan 2013 15:36:30 -0500 Received: by mail-oa0-f42.google.com with SMTP id j1so2930709oag.29 for ; Sat, 12 Jan 2013 12:36:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=4MR6Un0EJ3znBC4zlA542/xPIpVOvUFS6mG75hvF6GM=; b=HWtYpEMMQmc7yd0sgubnh5z0vn4hP7Bde2qr2cFZGyU+7/Z3B+DLjcKXKxo86AgL2B IzJPmZzryq6EXfw5FDNfxNrvkZfG/HW7AzVQQndJHVtPZEIcDZQnRdj+rzgyWXtoUTof l2/1eb57hI0H1SRiYXmbfHuXdVPE69CBq2lRbXe4mqo3ImFtxdEDlgyHslmtOAhXXjje M8q58V9yXy/ayW5o5j1ItJWGs4+ClEUuesIaih/7w8WSE1/WXcsGulHUOW3NupuHfKyu dQKW6Ii+RMVivI93aGc3FW2YdoW9SUX+seA5NOJzddg0M27AXnUt9MpCOhaBC2a0zLD2 NtiQ== Received: by 10.60.23.200 with SMTP id o8mr46981503oef.48.1358022987101; Sat, 12 Jan 2013 12:36:27 -0800 (PST) MIME-Version: 1.0 Received: by 10.76.167.162 with HTTP; Sat, 12 Jan 2013 12:35:47 -0800 (PST) In-Reply-To: <06.87.24230.C3291F05@pb1.pair.com> References: <06.87.24230.C3291F05@pb1.pair.com> Date: Sat, 12 Jan 2013 20:35:47 +0000 Message-ID: To: Ben Ramsey Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [VOTE] array_column() function From: petercowburn@gmail.com (Peter Cowburn) On 12 January 2013 16:41, Ben Ramsey wrote: > > I must have misread the Git Workflow page of the wiki, which states: > > "A patch will be applied to the oldest possible branch. If the Release > Manager of 5.3 accepts the change, commit it to the 5.3 branch. We will use > regular merging between the release branches." > > I can submit a new pull request against the master branch, if that's > acceptable. This is intended for 5.5. > The wiki is a little unclear there. The "oldest possible branch" against which this can be applied is, theoretically, PHP 5.5 according to the release process that was agreed to. In all likelihood, it could be added to 5.4 with the RMs consent. So the "oldest possible branch" is going to be one of those, not 5.3 nor master. One extra little detail that would be handy (at least for my own considered use of this new function) would be able to utilise the existing keys of the target array rather than relying on new 0-indexed keys or values from sub-arrays. $array = [ 123 => ['Chuck', 'Norris'], 310 => ['Sylvester', 'Stallone'], 736 => ['Jason', 'Statham'] ]; $first_names = array_column($array, 0, true); // 3rd param used as "preserve keys" (default = false) // [123 => 'Chuck', 310 => 'Sylvester', 736 => 'Jason'] The above is not really an issue, given array_keys() and array_combine() [though one neat function call would be nice], but it becomes most useful when the resulting array has fewer values than the original. To take your example from the RFC: $mismatchedColumns = array( array( 'a' => 'foo', 'b' => 'bar', 'e' => 'baz' ), array( 'a' => 'qux', 'c' => 'quux', 'd' => 'corge' ), array( 'a' => 'grault', 'b' => 'garply', 'e' => 'waldo' ), ); $b = array_column($mismatchedColumns, 'b', true); // 3rd param used as "preserve keys" (default = false) // [0 => 'bar', 2 => 'garply'] Note how that has keys [0, 2]. So the idea is to potentially change the $indexKey parameter from string|int to bool|string|int where: - false => same as null or not using the argument: uses 0-based keys (as RFC currently does) - true => uses keys from $input (suggested addition) - int|string => uses sub-array's $indexKey'th value as key (or 0-based for missing value, as RFC currently does) Thoughts?