php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9794 array_keys resets the array pointer and can not be used when looping
Submitted: 2001-03-16 12:13 UTC Modified: 2001-03-16 14:35 UTC
From: danbeck at dealnews dot com Assigned: andrei (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: linux 2.2.16
Private report: No CVE-ID: None
 [2001-03-16 12:13 UTC] danbeck at dealnews dot com
The following code is broken:

$arr = array("a", "b", "c");
foreach ($arr as $a) {
  echo "$a<BR>\n";
  echo max(array_keys($arr));
}

It stops after the first array element because array_keys resets the array pointer. (Or at least it's moved to the end...)

This is sort of a (repectful) complaint that I have about PHP and they way it's been written.  Arrays are systematically prostituted by the array functions because each one of them sees fit to reset the array pointer instead of just working off of a copy, or at the very least, returning the array pointer to it's previous state.

Is there some reason that the array pointer can't be returned to it's previous state after the array functions are finished with it?

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-16 12:29 UTC] sniper@php.net
I'll fix this problem soon. It's even in the TODO.

(on behalf of Andrei..so that he doesn't forget this.. :)

--Jani

 [2001-03-16 14:35 UTC] andrei@php.net
This problem has been fixed in CVS for all relevant array functions.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 01:01:30 2024 UTC