Req #63049 [Com]: iterator_to_array for recursive iterators

From: Date: Fri, 21 Dec 2012 13:23:38 +0000
Subject: Req #63049 [Com]: iterator_to_array for recursive iterators
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-175526@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=63049&edit=1 ID: 63049 Comment by: franssen dot roland at gmail dot com Reported by: franssen dot roland at gmail dot com Summary: iterator_to_array for recursive iterators Status: Open Type: Feature/Change Request Package: SPL related Operating System: Ubuntu PHP Version: 5.4.6 Block user comment: N Private report: N New Comment: I currently have this... which also isn't restricted to just \RecursiveIterator(s) but uses a more generic approach. <?php 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; } Previous Comments: ------------------------------------------------------------------------ [2012-12-21 10:35:43] datibbaw@php.net Ignore my previous comment. That would flatten the array instead. My apologies. ------------------------------------------------------------------------ [2012-12-21 10:29:57] datibbaw@php.net Why not just do this instead? iterator_to_array(new RecursiveIteratorIterator($it)); ------------------------------------------------------------------------ [2012-09-09 12:14:49] franssen dot roland at gmail dot com Description: ------------ It would be nice to have a recursive_iterator_to_array function to transform a \RecursiveIterator to a full recursive array... ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63049&edit=1

« previous php.bugs (#175526) next »