Re: Re: array_last_key() function
| From: | Gustavo Lopes | Date: | Sat, 14 Jul 2012 17:05:43 +0000 |
| Subject: | Re: Re: array_last_key() function | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-61228@lists.php.net to get a copy of this message | ||
Em Sat, 14 Jul 2012 04:04:27 +0200, Anthony Ferrara <ircmaxell@gmail.com> escreveu:
Why is the last key special? Why not a function to get the first or the penultimate key? Of course, there is one aspect where the first and last keys are special -- if you have some algorithm where you pop or shift the array successively. But in that case the argument about end() + key() having side effects is irrelevant because you are changing the array anyway. -- Gustavo LopesI like this idea. array_first_key would be nice too I am probably missing something, but what those would allow to do that rewind/end+key() doesn't do?The big thing that it does that end()+key() doesn't do is really what it doesn't do (update the internal pointer). end() modifies the array pointer. So if you try this in user-land: function array_last_key(array $array) {end($array); return key($array);} It will always force a full copy of the array (at least the hash table). Implementing this as a core function however would eliminate that one side-effect...