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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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: Thu Apr 25 07:01:31 2024 UTC