note 101321 added to class.arrayiterator
| From: | foobuilder at gmail dot com | Date: | Thu, 09 Dec 2010 19:01:25 +0000 |
| Subject: | note 101321 added to class.arrayiterator | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-174756@lists.php.net to get a copy of this message | ||
Unsetting all keys of an ArrayItem within foreach will always leave the second key:
<?php
$items = new ArrayObject(range(0, 9));
while (list($k, $v) = each($items)) {
unset($items[$k]);
}
print_r($items);
// ArrayIterator Object
// (
// [storage:ArrayIterator:private] => Array
// (
// [1] => 1
// )
// )
?>
I'm not sure if this is a bug as unsetting keys within foreach is usually a bad idea to begin
with (use while instead), but it's something to be aware of.
----
Server IP: 64.71.164.2
Probable Submitter: 173.13.145.110
----
Manual Page -- http://www.php.net/manual/en/class.arrayiterator.php
Edit -- https://master.php.net/note/edit/101321
Del: integrated -- https://master.php.net/note/delete/101321/integrated
Del: useless -- https://master.php.net/note/delete/101321/useless
Del: bad code -- https://master.php.net/note/delete/101321/bad+code
Del: spam -- https://master.php.net/note/delete/101321/spam
Del: non-english -- https://master.php.net/note/delete/101321/non-english
Del: in docs -- https://master.php.net/note/delete/101321/in+docs
Del: other reasons-- https://master.php.net/note/delete/101321
Reject -- https://master.php.net/note/reject/101321
Search -- https://master.php.net/manage/user-notes.php