Skip to content

Instantly share code, notes, and snippets.

@line-o
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save line-o/9890084 to your computer and use it in GitHub Desktop.
Save line-o/9890084 to your computer and use it in GitHub Desktop.
flatten multi-dimensional array in PHP
<?php
$multiDim = array(
array('one', 'two', 'three'),
array('four', 'five', 'six'),
);
$flatten = function ($list, $next) use (&$flatten) {
if (is_array($next)) {
return array_reduce($next, $flatten, $list);
}
array_push($list, $next);
return $list;
};
$flat = array_reduce($multiDim, $flatten, array());
print_r( $flat);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment