Skip to content

Instantly share code, notes, and snippets.

@tcz
Created May 21, 2013 10:09
Show Gist options
  • Save tcz/5618763 to your computer and use it in GitHub Desktop.
Save tcz/5618763 to your computer and use it in GitHub Desktop.
Demonstrating why RecursiveArrayIterator is useless whent he items are objects.
<?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