|  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.7 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
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-2024 The PHP Group
All rights reserved.
Last updated: Sun Jul 21 19:01:34 2024 UTC