Skip to content

Commit

Permalink
fix for issue php-edifact#92
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanrosnizek committed Nov 17, 2020
1 parent 3449ade commit 9c6bae2
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/EDI/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -228,7 +243,7 @@ public function disableUNA()
*
* @return string
*/
private function escapeValue(&$str): string
private function escapeValue(&$strOrArray)
{
$search = [
$this->symbRel,
Expand All @@ -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);
}
}

0 comments on commit 9c6bae2

Please sign in to comment.