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

 [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: Tue May 07 02:01:30 2024 UTC