$array) { foreach ($array as $key => $item) { if (!isset($out[$key])) { $out[$key] = $empty; } $out[$key][$subkey] = $item; } } return $out; } }