|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63049 recursive_iterator_to_array for recursive iterators
Submitted: 2012-09-09 12:14 UTC Modified: 2018-08-23 01:04 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: franssen dot roland at gmail dot com Assigned:
Status: Open Package: SPL related
PHP Version: 5.4.6 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: franssen dot roland at gmail dot com
New email:
PHP Version: OS:


 [2012-09-09 12:14 UTC] franssen dot roland at gmail dot com
It would be nice to have a recursive_iterator_to_array function to transform a \RecursiveIterator to a full recursive array...


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-21 10:29 UTC]
Why not just do this instead?

iterator_to_array(new RecursiveIteratorIterator($it));
 [2012-12-21 10:35 UTC]
Ignore my previous comment. That would flatten the array instead. My apologies.
 [2012-12-21 13:23 UTC] franssen dot roland at gmail dot com
I currently have this... which also isn't restricted to just \RecursiveIterator(s) but uses a more generic approach.

function recursive_iterator_to_array(\Traversable $it)
    $result = array();
    foreach($result as $key => $value) {
        if($value instanceof \Traversable) {
            $result[$key] = recursive_iterator_to_array($value);
        } else {
            $result[$key] = $value;
    return $result;
 [2013-08-25 09:14 UTC] stanislav at nechutny dot net
TO: franssen dot roland

In your code is error. On line 5 it should be "foreach($it as $key => $value) {"
 [2018-08-23 01:04 UTC]
-Summary: iterator_to_array for recursive iterators +Summary: recursive_iterator_to_array for recursive iterators
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 16 19:03:35 2021 UTC