From 9c6bae229096d316f16c588962d8e0e69e280d70 Mon Sep 17 00:00:00 2001 From: stefanrosnizek Date: Tue, 17 Nov 2020 13:59:29 +0100 Subject: [PATCH] fix for issue php-edifact#92 --- src/EDI/Encoder.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/EDI/Encoder.php b/src/EDI/Encoder.php index 275e2e14..0c9db0d3 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); } }