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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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: Sat Dec 14 07:01:24 2019 UTC