PHPackages                             loophp/iterators - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. loophp/iterators

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

loophp/iterators
================

The missing PHP iterators.

3.2.1(1y ago)38463.7k↓13.1%6[2 PRs](https://github.com/loophp/iterators/pulls)3MITPHPPHP &gt;= 8.1CI passing

Since Dec 15Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/loophp/iterators)[ Packagist](https://packagist.org/packages/loophp/iterators)[ Docs](https://github.com/loophp/iterators)[ GitHub Sponsors](https://github.com/drupol)[ RSS](/packages/loophp-iterators/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (5)Versions (62)Used By (3)

[![Latest Stable Version](https://camo.githubusercontent.com/7236270e864a28a8011ca3c706eb5c23463386b3b318014311738b3e07cff501/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6f7068702f6974657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/iterators)[![GitHub stars](https://camo.githubusercontent.com/e227a9b4ddc4b6ae71f34530de09e69080c8c8ec32033d324668abf08217e96b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6c6f6f7068702f6974657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/iterators) [![Total Downloads](https://camo.githubusercontent.com/72048c8eff5b1b2e43eafb724da308672d83f35b470a3a30a9bb6ba4cb866d6a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6f7068702f6974657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/iterators)[![GitHub Workflow Status](https://camo.githubusercontent.com/31e2d5901639d60da1081db2eb62525a7c19f8176411a5750002d494b0316c8d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6f6f7068702f6974657261746f72732f74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/loophp/iterators/actions)[![Type Coverage](https://camo.githubusercontent.com/890fca4ad711082bb3ebccec11f09f516d926cd6871bc4b6f55aaf0cd9bf4e51/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f64796e616d69632f6a736f6e3f7374796c653d666c61742d73717561726526636f6c6f723d636f6c6f72266c6162656c3d54797065253230636f7665726167652671756572793d6d6573736167652675726c3d687474707325334125324625324673686570686572642e6465762532466769746875622532466c6f6f7068702532466974657261746f7273253246636f766572616765)](https://shepherd.dev/github/loophp/iterators) [![License](https://camo.githubusercontent.com/6cd66991fd8c24e7e2f0b8f046a4faa09aa189b314670abf717d998f6dc9b92e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6f6f7068702f6974657261746f72732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/loophp/iterators)[![Donate!](https://camo.githubusercontent.com/a71f45de7e408be2477113d166e9ee94c90bbf814a1373fd154aa5b6652302de/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53706f6e736f722d4769746875622d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/sponsors/drupol)

PHP Iterators
=============

[](#php-iterators)

Description
-----------

[](#description)

The missing PHP iterators.

Features
--------

[](#features)

- `CachingIteratorAggregate`
- `ChunkIterableAggregate`
- `ClosureIterator`: `ClosureIterator(callable $callable, array $arguments = [])`
- `ClosureIteratorAggregate`: `ClosureIteratorAggregate(callable $callable, array $arguments = [])`
- `ConcatIterableAggregate`
- `FilterIterableAggregate`
- `InterruptableIterableIteratorAggregate`: `InterruptableIterableIteratorAggregate(iterable $iterable)`
- `IterableIterator`: `IterableIterator(iterable $iterable)`
- `IterableIteratorAggregate`: `IterableIteratorAggregate(iterable $iterable)`
- `MapIterableAggregate`
- `MersenneTwisterRNGIteratorAggregate`
- `MultipleIterableAggregate`
- `PackIterableAggregate`
- `PausableIteratorAggregate`
- `RandomIterableAggregate`
- `RecursiveIterableAggregate`
- `ReductionIterableAggregate`
- `ResourceIteratorAggregate`
- `SimpleCachingIteratorAggregate`
- `SortIterableAggregate`
- `StringIteratorAggregate`
- `TypedIterableAggregate`
- `UniqueIterableAggregate`
- `UnpackIterableAggregate`

Installation
------------

[](#installation)

`composer require loophp/iterators`

Usage
-----

[](#usage)

### CachingIteratorAggregate

[](#cachingiteratoraggregate)

Let you cache any iterator. You then get [\\Generators](https://www.php.net/generator) rewindable for free.

This implementation does not use internal state to keep track of the current position of the iterator. The underlying mechanism is based on [SPL \\CachingIterator](https://www.php.net/cachingiterator).

The pros of using that iterator is **performance**. It's blazing fast, it cannot compare to any other stateful custom implementations.

This iterator will cache keys and values, of any type.

```
