PHPackages                             elliotchance/iterator - 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. elliotchance/iterator

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

elliotchance/iterator
=====================

Iterator builders for PHP

v1.1.0(8y ago)453.6k↓43.1%2[1 issues](https://github.com/elliotchance/iterator/issues)2MITPHP

Since Dec 30Pushed 8y ago2 watchersCompare

[ Source](https://github.com/elliotchance/iterator)[ Packagist](https://packagist.org/packages/elliotchance/iterator)[ RSS](/packages/elliotchance-iterator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (2)

iterator
========

[](#iterator)

[![Build Status](https://camo.githubusercontent.com/f22dc3a33ed5694cc3025b00cb2629c9e799ed5dead3dfcb616b265dead0227e/68747470733a2f2f7472617669732d63692e6f72672f656c6c696f746368616e63652f6974657261746f722e7376673f6272616e63683d76312e30)](https://travis-ci.org/elliotchance/iterator)[![Coverage Status](https://camo.githubusercontent.com/0628a784c9214281e953d9f7b82ae14bcf073cc5f62873d7de3faa3ecc6c44a3/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f656c6c696f746368616e63652f6974657261746f722f62616467652e706e67)](https://coveralls.io/r/elliotchance/iterator)[![Latest Stable Version](https://camo.githubusercontent.com/72931e4e53d7cd4585864420be77647ceda9a001edcb2d0703d8acc8d18088e7/68747470733a2f2f706f7365722e707567782e6f72672f656c6c696f746368616e63652f6974657261746f722f762f737461626c652e737667)](https://packagist.org/packages/elliotchance/iterator)[![Total Downloads](https://camo.githubusercontent.com/f88431d9ed137b5357d84a378faae107dacb1a37d79378d74368d8cb42a20618/68747470733a2f2f706f7365722e707567782e6f72672f656c6c696f746368616e63652f6974657261746f722f646f776e6c6f6164732e737667)](https://packagist.org/packages/elliotchance/iterator)[![License](https://camo.githubusercontent.com/9617f36e3c47b0029a9ce71b97e3dc0d819c68cdfde17e1e125e5f53ba313249/68747470733a2f2f706f7365722e707567782e6f72672f656c6c696f746368616e63652f6974657261746f722f6c6963656e73652e737667)](https://packagist.org/packages/elliotchance/iterator)

Iterator builders for PHP.

```
use Elliotchance\Iterator\AbstractPagedIterator;

class MyPagedIterator extends AbstractPagedIterator
{
    /**
     * The total number of items we expect to find. The last page may be partial.
     * @return integer
     */
    public function getTotalSize()
    {
        return 8;
    }

    /**
     * The number of items per page. All pages must be the same size (except the
     * last page).
     * @return integer
     */
    public function getPageSize()
    {
        return 3;
    }

    /**
     * Lazy-load a specific page.
     * @return array
     */
    public function getPage($pageNumber)
    {
        $pages = [
            [ 1, 2, 3 ],
            [ 4, 5, 6 ],
            [ 7, 8 ],
        ];
        return $pages[$pageNumber];
    }
}
```

Now you can operate on it just as if were an array:

```
$iterator = new MyPagedIterator();
echo $iterator[4]; // 5

foreach ($iterator as $item) {
    echo $item;
}
// 1 2 3 4 5 6 7 8 9
```

It's important to note that pages are cached internally after first access. This makes it ideal for APIs that will only do one API request per page no matter what the items order requested is:

```
use Elliotchance\Iterator\AbstractPagedIterator;

class GithubSearcher extends AbstractPagedIterator
{
    protected $totalSize = 0;
    protected $searchTerm;

    public function __construct($searchTerm)
    {
        $this->searchTerm = $searchTerm;

        // this will make sure totalSize is set before we try and access the data
        $this->getPage(0);
    }

    public function getTotalSize()
    {
        return $this->totalSize;
    }

    public function getPageSize()
    {
        return 100;
    }

    public function getPage($pageNumber)
    {
        $url = "https://api.github.com/search/repositories?" . http_build_query([
            'q' => 'fridge',
            'page' => $pageNumber + 1
        ]);
        $result = json_decode(file_get_contents($url), true);
        $this->totalSize = $result['total_count'];
        return $result['items'];
    }
}

$repositories = new GithubSearcher('fridge');
echo "Found " . count($repositories) . " results:\n";
foreach ($repositories as $repo) {
    echo $repo['full_name'];
}
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity34

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1045 days

Total

2

Last Release

3112d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/86140?v=4)[Chao](/maintainers/chancey)[@chancey](https://github.com/chancey)

---

Top Contributors

[![elliotchance](https://avatars.githubusercontent.com/u/927418?v=4)](https://github.com/elliotchance "elliotchance (24 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/elliotchance-iterator/health.svg)

```
[![Health](https://phpackages.com/badges/elliotchance-iterator/health.svg)](https://phpackages.com/packages/elliotchance-iterator)
```

###  Alternatives

[kongulov/nova-tab-translatable

Making Nova Tab Translatable

8559.5k2](/packages/kongulov-nova-tab-translatable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
