public static function pregSplitArray(array $list, string $pattern): array
    {
        $slices = [];
        $index = -1;
        foreach ($list as $value) {
            if (preg_match($pattern, $value) === 1) {
                ++$index;
            }

            if ($index !== -1) {
                $slices[$index][] = $value;
            }
        }

        return $slices;
    }
public static function pregSplitArray(array $list, string $pattern): array
    {
        $slices = [];
        $index = -1;
        foreach ($list as $value) {
            if (preg_match($pattern, $value) === 1) {
                ++$index;
            }

            if ($index !== -1) {
                $slices[$index][] = $value;
            }
        }

        return $slices;
    }
public static function pregSplitArray ( array $ list , string $ pattern ) : array { $ slices = [ ] ; $ index = - 1 ; foreach ( $ list as $ value ) { if ( preg_match ( $ pattern , $ value ) === 1 ) { ++ $ index ; } if ( $ index !== - 1 ) { $ slices [ $ index ] [ ] = $ value ; } } return $ slices ; }
explode an array by lines that match a regular expression

@param string[] $list  a flat array
@param string $pattern a regular expression

@return string[]
explode an array by lines that match a regular expression