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

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

gacek85/collection-iterator
===========================

Helps iterating big sets of data

1.0.1(9y ago)021PHPPHP &gt;=5.5

Since Sep 29Pushed 9y ago1 watchersCompare

[ Source](https://github.com/gacek85/collection-iterator)[ Packagist](https://packagist.org/packages/gacek85/collection-iterator)[ RSS](/packages/gacek85-collection-iterator/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (4)Versions (2)Used By (0)

[![Build Status](https://camo.githubusercontent.com/530c6619334e774571928b4ec576f79cb87b45161bdfeea7496c3711c8ecd335/68747470733a2f2f7472617669732d63692e6f72672f676163656b38352f636f6c6c656374696f6e2d6974657261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/gacek85/collection-iterator)

\#Collection Iterator

An implementation of `SPL's` `Iterator` for traversing large collections of data minimising the risk of memory limit exhaustion. Consists of an iterator service class `Gacek85\Collection\CollectionIterator` and an interface `Gacek85\Collection\IterableDataProvider` for a provider that will be providing chunks of data to the iterator service.

\##How it works

The iterator loads the data using the provider **chunk by chunk**, previously loaded data are wiped out of the memory by the garbage collector.

\##Public API

\###CollectionIterator

```
setPerPage(int $perPage): CollectionIterator // Sets the number of items loaded at once
count(): int	// Returns the total count of the elements that will be traversed
```

Other public methods are `Iterator` specific API.

\###IterableDataProvider

```
getTotal(): int // Returns the total count of available elements
getChunk(int $offset, int $limit): array|Iterator //Returns the chunk of data from given offset limited with given limit
```

\##Usage

```
