public static function splitMultiMessage(string $ediMessage): array
    {
        // init
        $splicedMessages = [];
        $message = [];
        $unb = false;

        foreach (self::unwrap($ediMessage) as $segment) {

            if (\strpos($segment, 'UNB') === 0) {
                $unb = $segment;
                continue;
            }

            if (\strpos($segment, 'UNH') === 0) {
                if ($unb) {
                    $message[] = $unb;
                }
                $message[] = $segment;
                continue;
            }

            if (\strpos($segment, 'UNT') === 0) {
                $message[] = $segment;
                $splicedMessages[] = $message;
                $message = [];
                continue;
            }

            if ($message) {
                $message[] = $segment;
            }
        }

        if (\strpos($segment, 'UNZ') === 0) {
            $segment = \preg_replace('#UNZ\+\d+\+#', 'UNZ+1+', $segment);
            foreach ($splicedMessages as $k => $message) {
                $splicedMessages[$k][] = $segment;
            }
        }

        foreach ($splicedMessages as $k => &$message) {
            $message = \implode(PHP_EOL, $splicedMessages[$k]);
        }

        return $splicedMessages;
    }
public static function splitMultiMessage(string $ediMessage): array
    {
        // init
        $splicedMessages = [];
        $message = [];
        $unb = false;

        foreach (self::unwrap($ediMessage) as $segment) {

            if (\strpos($segment, 'UNB') === 0) {
                $unb = $segment;
                continue;
            }

            if (\strpos($segment, 'UNH') === 0) {
                if ($unb) {
                    $message[] = $unb;
                }
                $message[] = $segment;
                continue;
            }

            if (\strpos($segment, 'UNT') === 0) {
                $message[] = $segment;
                $splicedMessages[] = $message;
                $message = [];
                continue;
            }

            if ($message) {
                $message[] = $segment;
            }
        }

        if (\strpos($segment, 'UNZ') === 0) {
            $segment = \preg_replace('#UNZ\+\d+\+#', 'UNZ+1+', $segment);
            foreach ($splicedMessages as $k => $message) {
                $splicedMessages[$k][] = $segment;
            }
        }

        foreach ($splicedMessages as $k => &$message) {
            $message = \implode(PHP_EOL, $splicedMessages[$k]);
        }

        return $splicedMessages;
    }
public static function splitMultiMessage ( string $ ediMessage ) : array { // init $ splicedMessages = [ ] ; $ message = [ ] ; $ unb = false ; foreach ( self :: unwrap ( $ ediMessage ) as $ segment ) { if ( \ strpos ( $ segment , 'UNB' ) === 0 ) { $ unb = $ segment ; continue ; } if ( \ strpos ( $ segment , 'UNH' ) === 0 ) { if ( $ unb ) { $ message [ ] = $ unb ; } $ message [ ] = $ segment ; continue ; } if ( \ strpos ( $ segment , 'UNT' ) === 0 ) { $ message [ ] = $ segment ; $ splicedMessages [ ] = $ message ; $ message = [ ] ; continue ; } if ( $ message ) { $ message [ ] = $ segment ; } } if ( \ strpos ( $ segment , 'UNZ' ) === 0 ) { $ segment = \ preg_replace ( '#UNZ\+\d+\+#' , 'UNZ+1+' , $ segment ) ; foreach ( $ splicedMessages as $ k => $ message ) { $ splicedMessages [ $ k ] [ ] = $ segment ; } } foreach ( $ splicedMessages as $ k => & $ message ) { $ message = \ implode ( PHP_EOL , $ splicedMessages [ $ k ] ) ; } return $ splicedMessages ; }
Split multi messages to separate messages

@param string $ediMessage

@return array
Split multi messages to separate messages