php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52822 Function like current(), but advancing the internal array pointer by one
Submitted: 2010-09-13 01:50 UTC Modified: 2010-09-13 09:30 UTC
From: daniel dot alvarez at gmx dot de Assigned:
Status: Wont fix Package: *General Issues
PHP Version: 5.3.3 OS: Whatever
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: daniel dot alvarez at gmx dot de
New email:
PHP Version: OS:

 

 [2010-09-13 01:50 UTC] daniel dot alvarez at gmx dot de
Description:
------------
It would be great to have a function which is just like current, with the 
difference that it advances the array pointer to the next element after reading 
the current value.

When using current() in a loop, you always have to call next(). Including a 
function that acts like current() while automatically advancing the array 
pointer would be more elegant.

It can be implemented in PHP userland like this:

function currentPlusOne($array) {

    $element = current($array);

    next($array);

    return $element;
}

A native implementation among current(), next() etc. would be ideal, of course.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-09-13 09:30 UTC] aharvey@php.net
-Status: Open +Status: Wont fix
 [2010-09-13 09:30 UTC] aharvey@php.net
This is basically a value-only version of each() with the same problem that makes current() and next() more or less useless for iterating: false values can't be distinguished from the end of the array. I don't really think there's much need for yet another array function for something that's so easily done in userspace.

Closing won't fix.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 11:01:34 2025 UTC