Skip to content

Instantly share code, notes, and snippets.

@Kcko
Forked from kohnmd/flatten.php
Created February 26, 2017 09:27
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 Kcko/72ad727c2112315ee1315d29485ae73c to your computer and use it in GitHub Desktop.
Save Kcko/72ad727c2112315ee1315d29485ae73c to your computer and use it in GitHub Desktop.
Function to recursively flatten multidimensional PHP array.
<?php
// Requires PHP 5.3+
// Found here: http://stackoverflow.com/a/1320156
function flatten_array(array $array) {
$flattened_array = array();
array_walk_recursive($array, function($a) use (&$flattened_array) { $flattened_array[] = $a; });
return $flattened_array;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment