Re: [VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last()
| From: | Christoph M. Becker | Date: | Thu, 12 Jul 2018 22:12:26 +0000 |
| Subject: | Re: [VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last() | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102795@lists.php.net to get a copy of this message | ||
On 12.07.2018 at 09:06, Côme Chilliet wrote:
> Le jeudi 12 juillet 2018, 01:04:36 CEST Andrea Faulds a écrit :
>
>> Hmm. Returning null with no warning makes perfect sense for keys, since
>> null is not a valid key so there's no ambiguity, but for values it seems
>> problematic. On that ground I've decided to change my vote to No for the
>> value functions, but keep the vote for Yes for the key functions.
>> Someone who wants such behaviour could always do
>> ($array[array_key_last($array)] ?? null), I guess.
Ditto!
> You cannot do that easily if the array is returned by a function.
> function()[array_key_last(function())] would call the function twice.
You can easily store the function's return value in a variable, though.
--
Christoph M. Becker