|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-12-10 05:22 UTC] kosugi at kips dot gr dot jp
Description:
------------
ParentIterator that only shows those elements which have children.
But I can't get the expected result without rewind() in starting an iteration.
Reproduce code:
---------------
$target = array(
'foo' => array(1,2,3),
'bar' => array(11,12,13),
'baz'
);
$rai = new RecursiveArrayIterator($target);
$pi = new ParentIterator($rai);
//$pi->rewind();
while ($pi->valid()) {
var_dump($pi->current());
$pi->next();
}
Expected result:
----------------
array(5) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
array(5) {
[0]=>
int(11)
[1]=>
int(12)
[2]=>
int(13)
}
Actual result:
--------------
// no output
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 21:00:01 2025 UTC |
I got expected result with "this->rewind()" in constructor. class pi extends ParentIterator { public function __construct($iterator) { parent::__construct($iterator); $this->rewind(); } }