Hi all,

I just want to add some information that I feel it's missing in that discussion - I'm sorry if it was mentioned already.

1. It's already possible to extract the key and value of any index position of an array using array_slice: https://3v4l.org/mib99

2. "array_[key|value]_[first|last]($array)" is in my opinion not a good option as it lacks the possibility to extract key/value from any position. Something like "array_[key|value]_index($array, $index)" where $index would be the index position or negative index position from right.


Thanks,
Marc

Am 21.06.2018 um 18:16 schrieb Larry Garfield:
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


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to