php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39541 next_key() and prev_key()
Submitted: 2006-11-17 02:37 UTC Modified: 2021-11-16 17:24 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: boots@php.net Assigned: cmb (profile)
Status: Wont fix Package: *General Issues
PHP Version: 5.2.0 OS: all
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: boots@php.net
New email:
PHP Version: OS:

 

 [2006-11-17 02:37 UTC] 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.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-17 03:09 UTC] 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.
 [2021-11-16 17:24 UTC] cmb@php.net
-Status: Open +Status: Wont fix -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: cmb
 [2021-11-16 17:24 UTC] cmb@php.net
> 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>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 11:01:28 2024 UTC