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: 2006-11-17 03:09 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:
Status: Open Package: Feature/Change Request
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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Dec 06 05:01:23 2019 UTC