From df1b3068195edf01ac7c6553a959097241ed9ea6 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 6 May 2017 10:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E9=A1=B5=E7=B1=BB=E5=A2=9E=E5=8A=A0ea?= =?UTF-8?q?ch=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Paginator.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/library/think/Paginator.php b/library/think/Paginator.php index d3547f8b..92d70f04 100644 --- a/library/think/Paginator.php +++ b/library/think/Paginator.php @@ -273,6 +273,23 @@ abstract class Paginator implements ArrayAccess, Countable, IteratorAggregate, J return $this->items->isEmpty(); } + /** + * 给每个元素执行个回调 + * + * @param callable $callback + * @return $this + */ + public function each(callable $callback) + { + foreach ($this->items as $key => $item) { + if ($callback($item, $key) === false) { + break; + } + } + + return $this; + } + /** * Retrieve an external iterator * @return Traversable An instance of an object implementing Iterator or