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
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.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 08 06:01:23 2021 UTC