Skip to content

Instantly share code, notes, and snippets.

@shello
Created January 15, 2014 14:21
Show Gist options
  • Save shello/8437107 to your computer and use it in GitHub Desktop.
Save shello/8437107 to your computer and use it in GitHub Desktop.
<?php
// Adapted from http://stackoverflow.com/a/1320259
function array_flatten($array)
{
return iterator_to_array(
new RecursiveIteratorIterator(
new RecursiveArrayIterator($array)
),
false
);
}
// > flat(array(12, 3.45, 'ab', true, array('cd', 67, array(false))));
// → array(12, 3.4500000000000002, 'ab', true, 'cd', 67, false)
// > flat(array(12, 3.45, 'ab', true, array('cd', 67), null, 8, array(), 9));
// → array(12, 3.4500000000000002, 'ab', true, 'cd', 67, NULL, 8, 9)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment