Re: [RFC][Under Discussion] Add functions array_key_first()and array_key_last()
| From: | David Rodrigues | Date: | Thu, 21 Jun 2018 16:33:01 +0000 |
| Subject: | Re: [RFC][Under Discussion] Add functions array_key_first()and array_key_last() | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-102355@lists.php.net to get a copy of this message | ||
Brainstorm suggestions:
1. Keys being stored as reference:
$valueOutput = array_first(array $array, ?string &$keyOutput = null);
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);
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);
4. Specific method to return key instead of value:
array_first(array $array);
array_first_key(array $array);
5. Consider that keys could be obtained via array_keys(), so array_first()
should just care about values:
array_first(array_keys($array));
Em qui, 21 de jun de 2018 às 13:18, Larry Garfield <larry@garfieldtech..com>
escreveu:
> On Tuesday, June 19, 2018 9:47:01 PM CDT Levi Morrison wrote:
> > I don't think I'm getting all the mail I am supposed to. I hope this gets
> > seen.
> >
> > I propose 2 functions *only* which I believe covers the use-cases that
> > all 4 of these do and more, with shorter names, and the ability to
> > discern whether the call succeeded or not.
> >
> > list($key, $value) = array_first($input);
> > // $key will be null if the call failed
> >
> > list($key, $value) = array_last($input);
> > // $key will be null if the call failed
> >
> > I have tested it with user-land functions and seems to work as
> > intended in all success and failure conditions. Verification that it
> > works as intended with internal functions is necessary but this seems
> > a much better proposal to me.
>
> Can I vote "heck no" to any function that does multi-return, thus making
> it
> impossible to chain or pass directly to another function? That's an idiom
> that just doesn't make sense in PHP.
>
> --Larry Garfield
--
David Rodrigues