Kcko
2/26/2017 - 9:27 AM

Function to recursively flatten multidimensional PHP array.

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;
}