Req #39541 [Opn->Wfx]: next_key() and prev_key()
| From: | cmb@php.net | Date: | Tue, 16 Nov 2021 17:24:02 +0000 |
| Subject: | Req #39541 [Opn->Wfx]: next_key() and prev_key() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-237794@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=39541&edit=1
ID: 39541
Updated by: cmb@php.net
Reported by: boots@php.net
Summary: next_key() and prev_key()
-Status: Open
+Status: Wont fix
Type: Feature/Change Request
-Package: Feature/Change Request
+Package: *General Issues
Operating System: all
PHP Version: 5.2.0
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> This is inconvenient when looping through an array with the
> intention of comparing the current item to its immediate
> neighbors.
I wonder what actual use cases that would have; it's unlikely to
be common, and there are several ways to accomplish that without
introducing these new functions (e.g. for-loop over array_keys()).
Besides that, this feature request is 15 years old, and got almost
no traction, so I'm closing as WONTFIX. If you, or anybody else
for that matter, is still interested in this feature, please
pursue the RFC process[1].
[1] <https://wiki.php.net/rfc/howto>
Previous Comments:
------------------------------------------------------------------------
[2006-11-17 03:09:23] boots@php.net
As a minor request, it would be handy if PHP had analogues for the prev() and next() functions but
which instead returned keys without affecting the current array pointer.
Presently, one must use prev()/key() next()/key() and these both affect the array pointer which is
inconvenient when looping through an array with the intention of comparing the current item to its
immediate neighbors.
With next_key() and prev_key() one could get the keys and then directly lookup the neighboring items
without affecting the current position during looping.
------------------------------------------------------------------------
[2006-11-17 02:37:46] boots@php.net
Description:
------------
It would be handy if PHP had functions to get the current and previous keys in an array without
affecting the current array pointer. Presently, one must use prev()/key() next()/key() and these
both affect the array pointer. This is inconvenient when looping through an array with the intention
of comparing the current item to its immediate neighbors. Having next_key() and prev_key() would
allow one to directly lookup the neighboring items without affecting the current position while
looping.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=39541&edit=1