$array = [ 5, 6, 7, 8 ];
$array = [ 5, [ 6, [ 7, [ 8 ] ] ] ];
func recucive<Val>(vals: [Val]) -> [Any]? {
if let first = vals.first {
if let more = recucive(vals: Array<Val>(vals.dropFirst())) {
return [ first, more ]
}
return [ first ]
}
return nil
}
for ($i = count($array) - 1; $i >= 0; $i--) {
$result = empty($result) ? [$array[$i]] : [$array[$i], $result];
}