PHPackages                             isaeken/loops - 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. isaeken/loops

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

isaeken/loops
=============

Basic loops library

v3.1.3(4y ago)192975MITPHPPHP ^8.0

Since Sep 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/isaeken/loops)[ Packagist](https://packagist.org/packages/isaeken/loops)[ Docs](https://github.com/isaeken/loops)[ GitHub Sponsors](https://github.com/isaeken)[ RSS](/packages/isaeken-loops/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

Loops
=====

[](#loops)

[![Latest Version on Packagist](https://camo.githubusercontent.com/6879657429dbaf490e6f6f8b17512e0ab6d8a2db37a1811ae64569ea1994eb18/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f697361656b656e2f6c6f6f70732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/isaeken/loops)[![GitHub Tests Action Status](https://camo.githubusercontent.com/5a1779d8b96da7cc05959b6c33a43f8d4e47c7dc57f7f8a4a0c4e2c52591298c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f697361656b656e2f6c6f6f70732f72756e2d74657374733f6c6162656c3d7465737473)](https://github.com/isaeken/loops/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/0733cfebb585c8ae301606f8daaad480184b27e41224e35172234fce47636e24/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f697361656b656e2f6c6f6f70732f436865636b253230262532306669782532307374796c696e673f6c6162656c3d636f64652532307374796c65)](https://github.com/isaeken/loops/actions?query=workflow%3A%22Check+%26+fix+styling%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/f5b553026da5df84c9bd709700813185fba3ee57b96b856b60c39aadb29403e5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f697361656b656e2f6c6f6f70732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/isaeken/loops)

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

[](#installation)

You can install the package via composer:

```
composer require isaeken/loops
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
loop(5, function (\IsaEken\Loops\Index $index) {
    return $index->odd;
}); // [false, true, false, true, false]
```

### Async Usage

[](#async-usage)

```
$loop = async_loop(5, function (\IsaEken\Loops\Index $index) {
    return $index->even;
});

// ...

await($loop); // [true, false, true, false, true]
```

### Using with class method

[](#using-with-class-method)

```
$callback = new class implements \IsaEken\Loops\Contracts\LoopCallback {
    public function __invoke(Index $index, Loop $loop = null): int
    {
        return $index->index;
    }
};

$loop = new Loop(2, $callback);
$loop->run();
$loop->results(); // [0, 1]
```

### Get current loop

[](#get-current-loop)

```
loop(2 ,function (\IsaEken\Loops\Index $index, \IsaEken\Loops\Loop $loop) {
    return [
        'iteration' => $index->iteration,
        'index'     => $index->index,
        'remaining' => $index->remaining,
        'count'     => $index->count,
        'first'     => $index->first,
        'last'      => $index->last,
        'odd'       => $index->odd,
        'even'      => $index->even,
    ];
});
// [
//  [
//    'iteration' => 1,
//    'index' => 0,
//    'remaining' => 1,
//    'count' => 2,
//    'first' => true,
//    'last' => false,
//    'odd' => false,
//    'even' => true,
//  ],
//  [
//    'iteration' => 2,
//    'index' => 1,
//    'remaining' => 0,
//    'count' => 2,
//    'first' => false,
//    'last' => true,
//    'odd' => true,
//    'even' => false,
//  ]
// ]
```

### Break the loop

[](#break-the-loop)

```
loop(3, function (\IsaEken\Loops\Index $index, \IsaEken\Loops\Loop $loop) {
    if ($index->index > 1) {
        $loop->break();
    }

    return $index->index;
}); // [0, 1]
```

### Loop random times

[](#loop-random-times)

```
loop_random(function (\IsaEken\Loops\Index $index, \IsaEken\Loops\Loop $loop) {
    return $index->index;
}); // executed random times.

$min = 5;
$max = 10;

loop_random(function (\IsaEken\Loops\Index $index, \IsaEken\Loops\Loop $loop) {
    return $index->index;
}, $min, $max);
```

### Loop random with seed

[](#loop-random-with-seed)

```
loop_random(function (\IsaEken\Loops\Index $index) {
    return $index->even;
}, seed: 123456789);
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Isa Eken](https://github.com/isaeken)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 97.2% 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 ~26 days

Recently: every ~10 days

Total

6

Last Release

1596d ago

Major Versions

v1.0 → v2.02022-01-01

v2.2 → v3.12022-01-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/27427375a2832cfe00cf076041951fd56f9cafa9696e77887bee805101f49bb9?d=identicon)[isaeken](/maintainers/isaeken)

---

Top Contributors

[![isaeken](https://avatars.githubusercontent.com/u/57031552?v=4)](https://github.com/isaeken "isaeken (70 commits)")[![peter279k](https://avatars.githubusercontent.com/u/9021747?v=4)](https://github.com/peter279k "peter279k (2 commits)")

---

Tags

phplibraryloopsisaeken

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/isaeken-loops/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[illuminate/events

The Illuminate Events package.

13556.1M2.0k](/packages/illuminate-events)[illuminate/session

The Illuminate Session package.

9938.5M821](/packages/illuminate-session)[illuminate/pagination

The Illuminate Pagination package.

10533.5M989](/packages/illuminate-pagination)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.9M203](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.4M362](/packages/illuminate-redis)

PHPackages © 2026

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