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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 16:01:33 2024 UTC