note 96886 deleted from class.recursiveiteratoriterator by danbrown
| From: | danbrown@php.net | Date: | Sun, 21 Mar 2010 14:54:31 +0000 |
| Subject: | note 96886 deleted from class.recursiveiteratoriterator by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-167264@lists.php.net to get a copy of this message | ||
Note Submitter: kroccamen at gmail dot com
----
@crashrox
The default mode of RecursiveIteratorIterator is to recurse into arrays and *not* expose key =>
array to the loop; thus you can shorten your function to:
<?php
function array_flatten_recursive ($array) {
foreach (new RecursiveIteratorIterator (new RecursiveArrayIterator ($array)) as $key=>$value)
$flat[] = $value;
return $flat;
}
?>
Much nicer!
To expose key => array to the loop, use RecursiveIteratorIterator::SELF_FIRST as the second
parameter (as crashrox did).