php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #23701 optional parameter for reset() to reset all sub-arrays
Submitted: 2003-05-19 10:19 UTC Modified: 2013-10-28 07:44 UTC
From: kouber@php.net Assigned: krakjoe (profile)
Status: Closed Package: *General Issues
PHP Version: 4.3.2RC1 OS: Win2000NT
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: kouber@php.net
New email:
PHP Version: OS:

 

 [2003-05-19 10:19 UTC] kouber@php.net
<?
$array = array(array("a", "b"), array("c", "d"));

foreach ($array[1] as $key=>$value) {
	echo "Foreach cycle: ", $key, "=>", $value, "\n";
}

reset($array);  // Resets only the external array
// reset($array[1]);  // Resets $array[1] itself

while (list($key, $value) = each($array[1])) {
	echo "While cycle: ", $key, "=>", $value, "\n";
}
?>

The internal pointer of $array[1] is at the end of the array, so no output will be produced from the second cycle. I have to reset($array[1]), if I want it to be reset.

This is submitted once as a bug:
http://bugs.php.net/bug.php?id=37

I agree that it's the right behaviour of reset(), but if I want to explicitely reset all the sub-arrays of an array, I have to write too complicated cycles + condition checks, for such a basic thing like this.

It will be nice to have the option somewhere in the future (maybe as a second optional parameter) to reset all the internal arrays at once. ;)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-10-28 07:44 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Package: Feature/Change Request +Package: *General Issues -Assigned To: +Assigned To: krakjoe
 [2013-10-28 07:44 UTC] krakjoe@php.net
This doesn't belong as a feature of the reset function, it would be too open to infinite recursion to be useful, better that you manage this in user-land.

Closing the bug.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Sun Jun 14 19:00:01 2026 UTC