diff --git a/src/EDI/Encoder.php b/src/EDI/Encoder.php index 275e2e1..0c9db0d 100644 --- a/src/EDI/Encoder.php +++ b/src/EDI/Encoder.php @@ -138,7 +138,22 @@ public function encodeSegment(array $row): string unset($temp); } - $elm = \implode($this->sepComp, $iValue); + // implode (recursive) + $elm = ''; + \array_walk_recursive( + $iValue, + function ($value) use (&$elm) { + $elm .= $value . $this->sepComp; + } + ); + // removes last $glue from string + if ( + $elm + && + \strlen($this->sepComp) > 0 + ) { + $elm = \substr($elm, 0, -\strlen($this->sepComp)); + } } else { $elm = $this->escapeValue($iValue); } @@ -228,7 +243,7 @@ public function disableUNA() * * @return string */ - private function escapeValue(&$str): string + private function escapeValue(&$strOrArray) { $search = [ $this->symbRel, @@ -243,6 +258,6 @@ private function escapeValue(&$str): string $this->symbRel . $this->symbEnd, ]; - return \str_replace($search, $replace, (string) $str); + return \str_replace($search, $replace, $strOrArray); } }