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