function sort_array($array) { if ( is_array($array) ) { foreach ($array as $key => $data) { // Sort the rest of the levels by key if ( is_array($data) ) { // Sort the arrays inside the array // ksort($array[$key]); // Get recursive, baby! $array[$key] = sort_array($array[$key]); } else { } } } // Sort this level asort($array); ksort($array); // Regresar datos ordenados return $array; }