PHPackages                             crazycodr/previous-current-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. crazycodr/previous-current-iterator

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

crazycodr/previous-current-iterator
===================================

Simple package that offers an iterator used for previous vs current comparison

1.1.2(6y ago)011.0kMITPHP

Since Oct 2Pushed 6y agoCompare

[ Source](https://github.com/crazycodr/previous-current-iterator)[ Packagist](https://packagist.org/packages/crazycodr/previous-current-iterator)[ RSS](/packages/crazycodr-previous-current-iterator/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

[![Build Status](https://camo.githubusercontent.com/2663588094e6fc0cbe71b22e1f1eeba8ec25e6163a3363959a9264c80d44814b/68747470733a2f2f7472617669732d63692e6f72672f6372617a79636f64722f70726576696f75732d63757272656e742d6974657261746f722e737667)](https://travis-ci.org/crazycodr/previous-current-iterator)[![Latest Stable Version](https://camo.githubusercontent.com/ad58a668bf8967bd712d48950c3966869be8e4ba1cb0dcccfbee5e7e45ef6253/68747470733a2f2f706f7365722e707567782e6f72672f6372617a79636f64722f70726576696f75732d63757272656e742d6974657261746f722f762f737461626c65)](https://packagist.org/packages/crazycodr/previous-current-iterator) [![Total Downloads](https://camo.githubusercontent.com/8e19642cc2fc7eaa2d7c2fee9891abd38cf4cc64f0c329e50e298b14960c9c57/68747470733a2f2f706f7365722e707567782e6f72672f6372617a79636f64722f70726576696f75732d63757272656e742d6974657261746f722f646f776e6c6f616473)](https://packagist.org/packages/crazycodr/previous-current-iterator) [![Latest Unstable Version](https://camo.githubusercontent.com/0d4a20e701a8b13bd73bc05e4cf77b46534a342c6ec6ba327621c8ae5d2d12d4/68747470733a2f2f706f7365722e707567782e6f72672f6372617a79636f64722f70726576696f75732d63757272656e742d6974657261746f722f762f756e737461626c65)](https://packagist.org/packages/crazycodr/previous-current-iterator) [![License](https://camo.githubusercontent.com/ef8fac13f7226009d1eee7d7ef0dd47edcc6d84545dc8dd5bc7a997ec1e4d9b4/68747470733a2f2f706f7365722e707567782e6f72672f6372617a79636f64722f70726576696f75732d63757272656e742d6974657261746f722f6c6963656e7365)](https://packagist.org/packages/crazycodr/previous-current-iterator)

Previous/Current iterator
=========================

[](#previouscurrent-iterator)

Allows iteration over an array but returns two items at a time stepping by one item at a time. Thus, the iterator for

```
['a', 'b', 'c', 'd']
```

Will return

```
['previous' => 'a', 'current' => 'b']
['previous' => 'b', 'current' => 'c']
['previous' => 'c', 'current' => 'd']
```

Current/Next iterator
=====================

[](#currentnext-iterator)

Allows iteration over an array but returns two items at a time stepping by one item at a time. Thus, the iterator for

```
['a', 'b', 'c', 'd']
```

Will return

```
['current' => 'a', 'next' => 'b']
['current' => 'b', 'next' => 'c']
['current' => 'c', 'next' => 'd']
['current' => 'd', 'next' => null]
```

Installation
============

[](#installation)

To install it, just include this requirement into your composer.json

```
{
    "require": {
        "crazycodr/previous-current-iterator": "1.*"
    }
}
```

And then run composer install/update as necessary.

Supports
========

[](#supports)

Only PHP 5.5 or more can be supported due to the fact that key() can only return arrays starting with PHP 5.5!

Examples
========

[](#examples)

To use the PreviousCurrentIterator, just instanciate a copy with an array and foreach it!

```
$data = ['a', 'b', 'c', 'd'];
foreach(new PreviousCurrentIterator($data) as $keys => $values) {
    //Compare previous and current
    if ($values['previous'] !== $values['current']) {
        echo 'Not the same';
    }
}
```

To use the CurrentNextIterator, just instanciate a copy with an array and foreach it!

```
$data = ['a', 'b', 'c', 'd'];
foreach(new CurrentNextIterator($data) as $keys => $values) {
    //Compare previous and current
    if ($values['next'] !== null) {
        if ($values['current'] !== $values['next']) {
            echo 'Not the same';
        }
    }
}
```

Use cases
=========

[](#use-cases)

Practical if you need to compare two items together in a previous vs current or current vs next manner.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity66

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 ~459 days

Total

4

Last Release

2548d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a264166a26f76e0a35c096552dc773f8d90d8e1180bd65013234d9f42c021ff0?d=identicon)[crazycodr](/maintainers/crazycodr)

---

Top Contributors

[![crazycodr](https://avatars.githubusercontent.com/u/4398521?v=4)](https://github.com/crazycodr "crazycodr (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/crazycodr-previous-current-iterator/health.svg)

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

PHPackages © 2026

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