Skip to content

Instantly share code, notes, and snippets.

@mattkirwan
Created January 29, 2013 19:20
Show Gist options
  • Save mattkirwan/4666841 to your computer and use it in GitHub Desktop.
Save mattkirwan/4666841 to your computer and use it in GitHub Desktop.
Uses PHP's built in SPL Array Iterators to quickly spin through a multidimensional array and return a 'flattened' output.
<?php
function flattenArray( array $array )
{
$returned_array = array();
foreach( new \RecursiveIteratorIterator( new \RecursiveArrayIterator($array) ) as $key => $value )
{
$returned_array[] = $value;
}
return $returned_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment