ID: 32959
User updated by: ben at bravenet dot com
Reported By: ben at bravenet dot com
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: Ubuntu Hoary 5.04
PHP Version: 4.3.10
New Comment:
nm - just needed to read the manpage more carefully
Previous Comments:
------------------------------------------------------------------------
[2005-05-05 21:11:59] ben at bravenet dot com
Description:
------------
After a foreach() on an array, key() won't return a value from the same
array.
It looks like an internal array pointer problem, since a reset() before
key() appears to fix it.
Reproduce code:
---------------
<?php
$foo = array('a'=>'1', 'b'=>'2', 'c'=>'3');
foreach($foo as $k=>$v)
{
echo "$k=>$v\n";
}
// reset($foo); // this fixes the problem
echo key($foo);
?>
Expected result:
----------------
a=>1
b=>2
c=>3
a
Actual result:
--------------
a=>1
b=>2
c=>3
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=32959&edit=1