Created
May 21, 2013 10:09
-
-
Save tcz/5618763 to your computer and use it in GitHub Desktop.
Demonstrating why RecursiveArrayIterator is useless whent he items are objects.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$multi_array = array( | |
'foo' => array( | |
'bar' => (object) array( 'baz' => 'bat' ), | |
), | |
); | |
var_dump( iterator_to_array( new RecursiveIteratorIterator( new RecursiveArrayIterator( $multi_array ) ) ) ); | |
class RecursiveRealArrayIterator extends RecursiveArrayIterator | |
{ | |
public function hasChildren() | |
{ | |
$current = $this->current(); | |
return is_array( $current ) || $current instanceof Traversable; | |
} | |
} | |
var_dump( iterator_to_array( new RecursiveIteratorIterator( new RecursiveRealArrayIterator( $multi_array ) ) ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment