Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102512 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 80493 invoked from network); 28 Jun 2018 12:48:49 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2018 12:48:49 -0000 Authentication-Results: pb1.pair.com smtp.mail=enno.woortmann@web.de; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=enno.woortmann@web.de; sender-id=pass Received-SPF: pass (pb1.pair.com: domain web.de designates 212.227.17.11 as permitted sender) X-PHP-List-Original-Sender: enno.woortmann@web.de X-Host-Fingerprint: 212.227.17.11 mout.web.de Received: from [212.227.17.11] ([212.227.17.11:43163] helo=mout.web.de) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/59-01794-F29D43B5 for ; Thu, 28 Jun 2018 08:48:47 -0400 Received: from [10.129.18.221] ([194.76.42.30]) by smtp.web.de (mrweb102 [213.165.67.124]) with ESMTPSA (Nemesis) id 0LtWsC-1gFFdP2KVY-010sBp; Thu, 28 Jun 2018 14:48:43 +0200 To: David Rodrigues Cc: PHP Internals References: <75db877c-ef0b-7d3b-48a8-9879d90352b0@web.de> <3242366.BL9MUqXe46@vulcan> <2241856.Iz1GuBRvza@vulcan> Message-ID: Date: Thu, 28 Jun 2018 14:48:42 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------3A955248F938E6656D625399" X-Provags-ID: V03:K1:63yzDTY3EenwvgNgeYxrch1i3mJjy65Db3lSI2U17NtkbRAG8SQ zOg9ga7MsCXUmOQxVl2qIYe06t2LEYxCvaXVZPzB3ctlHYueULiZufPi4d1tdn31d4dUGPt SF1KWAxQgiev4IY2RZJGqMC4/uAtfxyQ7OdZJZvFxrtUS3xQ6eOcd6txJ54Bbwpho3Qgtz2 AHjgbbJEkPmQPbc0jKgmA== X-UI-Out-Filterresults: notjunk:1;V01:K0:ib7g8vWSjJ8=:Cu6zWXsSi4b/TIngp2yJ3Z OKe3l/Q5/apLCd1jioEgIBVsTKmSJPFsQoeSwjMofG2Wtf4sKXgImP48ZZs0emSH8TaK75cRT tEKZa1yGNYbcvMuzAoxZrBVA/fFbnY3sPBkN0eHTprcMwQiDR9T6dow13kbIcXdC9m5D7JJTj XC4IKHEyLLdhELRChFXNHnE2eVh44lAQoLGYjXhTiI1OwUBJIE8q0vRzNgZAlv22TJUiZ0hzW MC+wWiOkgKnLegbWjnxEdcmAmR48zQdH9aD1NJl87FCbQHcZme2TJ7gXxyLfJnsRQQjmox/Cm h2u2gzeAASzxtHRG+Q9L6kBNi0zx3EtVo1fX6maJjQ29as9a71hSGdXhWhbSchnyFOeYozKGu Q6vOtgqqWlY1Nb+y/71re0SIOkEQfnwIBZIi1z3QSaYefdfUSE9xDKDIrcgcRdAF3hVbw4E68 3GAbZMxPkkqvA+OHtKgZOuZ+vx5Y9e2g4wDNLbCdUibFzlozdTwnjfdHQM76GAjjvDvrkldLJ vl8+8tteCWL7JVsg+51grAYlnZWtl4i+4N+wkHgxY3j1uItVzRg9e3lymqWLRwvlgYiQ/YLsj CtUdyeTUR8kN4cCecziZZPM2s5QIIS+CwyqdgBKl0NGiO56yD3j/LDg/ptiq8d/zXiLDYmbvg WC4rMiFgwqQasn5Uc2l31BkpBmW0gHv+Nb1vOnNO7Gb/9rkpeZSQtIGNLwieM3eD8NnTNvRkD t6eGSFiN31lHr/fLwNrY7KbODd8KTSbOPLr/sAEcwp7Ee5ughWAzQHe6ThUFdJHpfuRTWI5s3 xy8jo5r Subject: Re: [PHP-DEV] [RFC][Under Discussion] Add functions array_key_first()and array_key_last() From: enno.woortmann@web.de ("Woortmann, Enno") --------------3A955248F938E6656D625399 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi David, thanks for your brainstorming suggestions. My opinion on the options: > 1. Keys being stored as reference: > > $valueOutput = array_first(array $array, ?string &$keyOutput = null); In my opinion using references to return additional values from a function is quiet hacky. I think returning a single value leads to significantly clearer code and thus supports the developer. > 2. Function will returns value or key, by option (similar to > array_filter()): > ​​ > array_first(array $array, int $options = ARRAY_VALUE); > ​ > array_first(array $array, int $options = ARRAY_KEY); ​ This violates the single responsibility principle and consequently isn't a good move > ​3. ​ > F > ​unction will returns value or key, by boolean argument: > > array_first(array $array, bool $returnKeyInsteadOfValue = false); > array_first(array $array, bool $returnKeyInsteadOfValue = true); ​ Compare 2. > 4. Specific method to return key instead of value: > > array_first(array $array); > array_first_key(array $array); This is the RFC just with slightly different function names. I think using array_key_first and array_value_first (and the corresponding functions for the last array element) provides a consistent naming. > 5. Consider that keys could be obtained via array_keys(), so array_first() > should just care about values: > > array_first(array_keys($array)); This solution requires a copy of the array (keys) which extends the time complexity and the memory usage of the task. Regards, Enno --------------3A955248F938E6656D625399--