$array * * @return array */ public static function flatten(iterable $array, float|int $depth = INF): array { $result = []; foreach ($array as $item) { if (!is_array($item)) { $result[] = $item; } else { $values = $depth === 1 ? array_values($item) : self::flatten($item, $depth - 1); foreach ($values as $value) { $result[] = $value; } } } return $result; } }