Re: Re:[VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last()
| From: | Côme Chilliet | Date: | Wed, 11 Jul 2018 08:18:10 +0000 |
| Subject: | Re: Re:[VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last() | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102746@lists.php.net to get a copy of this message | ||
Le mardi 10 juillet 2018, 18:41:17 CEST Levi Morrison a écrit :
> People who argue against the tuple because they don't like the design
> need to consider the bigger picture.
My guess is people arguing for the tuple do not understand the usecase :-)
Each time I felt the need for array_first_value was because I was using it on a function return to
do something with it.
Like:
if (array_first_value(some_function()) > 3) {
// do something
}
Either I know that the array is not empty, or I do not care because NULL will be ignored correctly.
In the second case, with a tuple I’m stuck because if I do:
if (array_first(some_function())[1] > 3) {
// do something
}
If array_first returns NULL this will trigger a PHP error. So I have to add more code to handle this
special case while I do not need any with array_first_value.
Côme