Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93623 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11435 invoked from network); 29 May 2016 14:02:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 May 2016 14:02:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=thomas@nunninger.info; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=thomas@nunninger.info; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nunninger.info from 87.106.55.207 cause and error) X-PHP-List-Original-Sender: thomas@nunninger.info X-Host-Fingerprint: 87.106.55.207 mail.nunninger.info Linux 2.6 Received: from [87.106.55.207] ([87.106.55.207:53769] helo=mail.nunninger.info) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 33/32-23584-776FA475 for ; Sun, 29 May 2016 10:02:32 -0400 Received: from p5093df94.dip0.t-ipconnect.de ([80.147.223.148] helo=[192.168.178.21]) by mail.nunninger.info with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.69) (envelope-from ) id 1b71H0-00088R-Ag; Sun, 29 May 2016 14:01:18 +0000 To: Colin O'Dell , PHP Internals References: Cc: jmikola@gmail.com Message-ID: <574AF60A.6070908@nunninger.info> Date: Sun, 29 May 2016 16:00:42 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Score: 0.6 (/) X-Spam-Several-Recipients: Yes Subject: Re: [PHP-DEV] [RFC Discussion] array_change_keys() From: thomas@nunninger.info (Thomas Nunninger) Hello, shouldn't it be possible to return null as new key? That way you say: Use the next free integer index. Not sure if returning null is wanted (as it could hide errors in the callback) or needed in some real world use cases. But it would be more in sync with $a[] = ... Regards Thomas On 05/29/2016 03:13 PM, Colin O'Dell wrote: > Hello everyone, > > I'd like to introduce a new RFC for your consideration and discussion: > https://wiki.php.net/rfc/array_change_keys This would add a new function > named array_change_keys() which simplifies the process of re-keying an > array. > > PHP currently has an array_change_key_case() method, but this only allows > keys to be changed to upper- or lower-case; no method exists to change the > keys to some custom user-defined value. Although it's absolutely possible > to accomplish this without a special function, the alternate approaches > have several drawbacks: > > - Slower execution time compared to the proposed implementation. > - Multiple lines and/or function calls are required. > - Harder to understand the code's purpose with a quick glance. > - The result of a "foreach" approach cannot be passed into another > function without using an intermediate variable. > > A working implementation has been included with the RFC (huge thanks to > Jeremy Mikola for the heavy lifting here!) I've also requested this patch > be added to 3v4l.org; I'll notify everyone if/when that happens. > > I'd greatly appreciate if you could review this RFC and let me know your > thoughts. I'd be happy to answer any questions you might have. > > Regards, > > Colin O'Dell >