note 126377 added to function.iterator-count
| From: | oleksii dot bulba at gmail dot com | Date: | Wed, 01 Sep 2021 07:20:38 +0000 |
| Subject: | note 126377 added to function.iterator-count | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216845@lists.php.net to get a copy of this message | ||
Be aware that counting over NoRewindIterator will make items unavailable:
<?php
$iterator = new ArrayIterator(['recipe'=>'pancakes', 'egg',
'milk', 'flour']);
$iterator = new NoRewindIterator($iterator);
var_dump($iterator->current());
var_dump(iterator_count($iterator));
var_dump($iterator->current());
$iterator->rewind(); // Does not work because it's NoRewindIterator
var_dump($iterator->current());
var_dump(iterator_count($iterator));
?>
Output:
<?php
/*
string(8) "pancakes"
int(4)
NULL
NULL
*/
int(0)
?>
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 37.214.70.200)
----
Manual Page -- https://php.net/manual/en/function.iterator-count.php
Edit -- https://main.php.net/note/edit/126377
Del: integrated -- https://main.php.net/note/delete/126377/integrated
Del: useless -- https://main.php.net/note/delete/126377/useless
Del: bad code -- https://main.php.net/note/delete/126377/bad+code
Del: spam -- https://main.php.net/note/delete/126377/spam
Del: non-english -- https://main.php.net/note/delete/126377/non-english
Del: in docs -- https://main.php.net/note/delete/126377/in+docs
Del: other reasons-- https://main.php.net/note/delete/126377
Reject -- https://main.php.net/note/reject/126377
Search -- https://main.php.net/manage/user-notes.php