From ce319ac73ad3184325ade367f0a1559bf113212c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=92=B1=E5=AE=87?= Date: Wed, 11 Sep 2024 18:08:45 +0800 Subject: [PATCH] commit --- src/GoodCodecCSV.php | 5 +++-- src/GoodCodecTSV.php | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/GoodCodecCSV.php b/src/GoodCodecCSV.php index 9398251..b8c553e 100644 --- a/src/GoodCodecCSV.php +++ b/src/GoodCodecCSV.php @@ -74,8 +74,9 @@ public static function csv_encode_row($row, $out_charset = "UTF-8", $in_charset $enclosure = isset($enclosure) ? $enclosure : "\""; $force_quote = isset($force_quote) ? $force_quote : 0; $s = ""; - foreach ($row as $idx => $str) { - if ($idx !== 0) { + $idx = -1; + foreach ($row as $str) { + if (++$idx !== 0) { $s .= $delimiter; } $s .= self::csv_encode_str($str, "UTF-8", $in_charset, 0, $null, $delimiter, $enclosure, $force_quote); diff --git a/src/GoodCodecTSV.php b/src/GoodCodecTSV.php index bbc0adc..f5af701 100644 --- a/src/GoodCodecTSV.php +++ b/src/GoodCodecTSV.php @@ -44,8 +44,9 @@ public static function tsv_encode_row($row, $out_charset = "UTF-8", $in_charset } $need_iconv = $in_charset !== "UTF-8"; $s = ""; - foreach ($row as $k => $str) { - if ($k != 0) { + $idx = -1; + foreach ($row as $str) { + if (++$idx !== 0) { $s .= "\t"; } if ($str === NULL) { @@ -75,8 +76,9 @@ public static function tsv_encode_table($data, $out_charset = "UTF-8", $in_chars $need_iconv = $in_charset !== "UTF-8"; $s = ""; foreach ($data as $row) { - foreach ($row as $k => $str) { - if ($k != 0) { + $idx = -1; + foreach ($row as $str) { + if (++$idx !== 0) { $s .= "\t"; } if ($str === NULL) {