From b115680a4d8ee43bd1adb36485fa69277a69231a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Tue, 5 Sep 2017 15:12:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E5=88=86=E9=A1=B5=E7=B1=BB?= =?UTF-8?q?=E5=92=8C=E6=95=B0=E6=8D=AE=E9=9B=86=E7=B1=BB=E7=9A=84each?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Collection.php | 5 ++++- library/think/Paginator.php | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/library/think/Collection.php b/library/think/Collection.php index 41b42759..d88c3183 100644 --- a/library/think/Collection.php +++ b/library/think/Collection.php @@ -189,8 +189,11 @@ class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSeria public function each(callable $callback) { foreach ($this->items as $key => $item) { - if ($callback($item, $key) === false) { + $result = $callback($item, $key); + if (false === $result) { break; + } elseif (!is_object($item)) { + $this->items[$key] = $result; } } diff --git a/library/think/Paginator.php b/library/think/Paginator.php index 6a9dfe41..39d2f644 100644 --- a/library/think/Paginator.php +++ b/library/think/Paginator.php @@ -288,8 +288,11 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J public function each(callable $callback) { foreach ($this->items as $key => $item) { - if ($callback($item, $key) === false) { + $result = $callback($item, $key); + if (false === $result) { break; + } elseif (!is_object($item)) { + $this->items[$key] = $result; } }