public function groupsExtract(string $start = 'LIN', array $barrier = ['UNS']): array
    {
        // init
        $groups = [];
        $group = [];
        $position = 'before_search';

        foreach ($this->getParsedFile() as $edi_row) {
            $segment = $edi_row[0];
            if (
                $position == 'group_is'
                &&
                (
                    $segment == $start
                    ||
                    \in_array($segment, $barrier, true)
                )
            ) {
                // end of group
                $groups[] = $group;
                // start new group
                $group = [];
                $position = 'group_finish';
            }

            if ($segment == $start) {
                $position = 'group_is';
            }

            // add element to group
            if ($position == 'group_is') {
                $group[] = $edi_row;
            }
        }

        return $groups;
    }
public function groupsExtract(string $start = 'LIN', array $barrier = ['UNS']): array
    {
        // init
        $groups = [];
        $group = [];
        $position = 'before_search';

        foreach ($this->getParsedFile() as $edi_row) {
            $segment = $edi_row[0];
            if (
                $position == 'group_is'
                &&
                (
                    $segment == $start
                    ||
                    \in_array($segment, $barrier, true)
                )
            ) {
                // end of group
                $groups[] = $group;
                // start new group
                $group = [];
                $position = 'group_finish';
            }

            if ($segment == $start) {
                $position = 'group_is';
            }

            // add element to group
            if ($position == 'group_is') {
                $group[] = $edi_row;
            }
        }

        return $groups;
    }
public function groupsExtract ( string $ start = 'LIN' , array $ barrier = [ 'UNS' ] ) : array { // init $ groups = [ ] ; $ group = [ ] ; $ position = 'before_search' ; foreach ( $ this -> getParsedFile ( ) as $ edi_row ) { $ segment = $ edi_row [ 0 ] ; if ( $ position == 'group_is' && ( $ segment == $ start || \ in_array ( $ segment , $ barrier , true ) ) ) { // end of group $ groups [ ] = $ group ; // start new group $ group = [ ] ; $ position = 'group_finish' ; } if ( $ segment == $ start ) { $ position = 'group_is' ; } // add element to group if ( $ position == 'group_is' ) { $ group [ ] = $ edi_row ; } } return $ groups ; }
Get groups from message when last segment is unknown but you know the barrier
useful for invoices by default.

@param string $start   first segment start a new group
@param array  $barrier barrier segment (NOT in group)

@return array
Get groups from message when last segment is unknown but you know the barrier useful for invoices by default .