From 8510c65124e49e46e28127ab254ba14f6b70aed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Wed, 4 Mar 2026 13:52:46 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E5=96=84=20str2arr/arr2str=20?= =?UTF-8?q?=E7=99=BD=E5=90=8D=E5=8D=95=E5=8C=B9=E9=85=8D=E4=B8=8E=E7=A9=BA?= =?UTF-8?q?=E7=99=BD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/think-library/src/common.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/think-library/src/common.php b/plugin/think-library/src/common.php index fbacbb67d..868b3dc92 100644 --- a/plugin/think-library/src/common.php +++ b/plugin/think-library/src/common.php @@ -201,8 +201,9 @@ if (!function_exists('str2arr')) { { $items = []; foreach (explode($separ, trim($text, $separ)) as $item) { - if ($item !== '' && (!is_array($allow) || in_array($item, $allow))) { - $items[] = trim($item); + $item = trim($item); + if ($item !== '' && (!is_array($allow) || in_array($item, $allow, true))) { + $items[] = $item; } } return $items; @@ -218,8 +219,11 @@ if (!function_exists('arr2str')) { function arr2str(array $data, string $separ = ',', ?array $allow = null): string { foreach ($data as $key => $item) { - if ($item === '' || (is_array($allow) && !in_array($item, $allow))) { + $item = is_string($item) ? trim($item) : $item; + if ($item === '' || (is_array($allow) && !in_array($item, $allow, true))) { unset($data[$key]); + } else { + $data[$key] = $item; } } return $separ . join($separ, $data) . $separ;