PHP 4.0 Bug #5822 Updated: key() skips the next key if element previously unset
| From: | Bug Database | Date: | Thu, 27 Jul 2000 19:04:00 +0000 |
| Subject: | PHP 4.0 Bug #5822 Updated: key() skips the next key if element previously unset | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-26565@lists.php.net to get a copy of this message | ||
ID: 5822
Updated by: zak
Reported By: nathan@cjhunter.com
Status: Closed
Bug Type: Misbehaving function
Assigned To:
Comments:
I do not believe that this is a bug. When you call unset, it shifts the elements under the unset
element (if any) up to replace the missing space.
So, c moves into b's spot, and then you call next...
<?
$a = array("a" => 1, "b" => 2, "c" => 3,
"d" => 4, "e" => 5);
reset($a);
while($key = key($a)){
echo "Current key before unset: $key";
if($a[$key] == 2){
unset($a[$key]);
}
print ' | Current key after unset '. key ($a) . '<br />';
next($a);
}
print '<pre>';
var_dump($a);
print '</pre>';
?>
Full Bug description available at: http://bugs.php.net/?id=5822