PHPackages                             midnite81/loopy - 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. midnite81/loopy

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

midnite81/loopy
===============

Adds functionality for iterables

1.0.1(4y ago)0378MITPHPPHP &gt;7.4

Since Aug 13Pushed 4y ago1 watchersCompare

[ Source](https://github.com/midnite81/loopy)[ Packagist](https://packagist.org/packages/midnite81/loopy)[ RSS](/packages/midnite81-loopy/feed)WikiDiscussions main Synced today

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

Loopy!
======

[](#loopy)

[![Latest Stable Version](https://camo.githubusercontent.com/76335443c4383290a8a70a039f2707f57c32569a85a63e0ae0714465a66269a5/68747470733a2f2f706f7365722e707567782e6f72672f6d69646e69746538312f6c6f6f70792f76657273696f6e)](https://packagist.org/packages/midnite81/loopy) [![Total Downloads](https://camo.githubusercontent.com/4590e2a47ba1698e9ceda87cb87d6d72dadfee966b2ae01710f78e8801ba16cd/68747470733a2f2f706f7365722e707567782e6f72672f6d69646e69746538312f6c6f6f70792f646f776e6c6f616473)](https://packagist.org/packages/midnite81/loopy) [![Latest Unstable Version](https://camo.githubusercontent.com/e80fcbf0c2daf10a27b573b12b79683837288f4478532f90371ae4f245379ee6/68747470733a2f2f706f7365722e707567782e6f72672f6d69646e69746538312f6c6f6f70792f762f756e737461626c65)](https://packagist.org/packages/midnite81/loopy) [![License](https://camo.githubusercontent.com/c914823f19bc063e7df74787aabcd20504ee4c789e25c31c373b8e5a064e1d33/68747470733a2f2f706f7365722e707567782e6f72672f6d69646e69746538312f6c6f6f70792f6c6963656e73652e737667)](https://packagist.org/packages/midnite81/loopy) [![Build](https://camo.githubusercontent.com/45a3787fdafd3f2a16538fc7ea13dfc48db8604e5366da05a76f0273a7d7eb0e/68747470733a2f2f7472617669732d63692e636f6d2f6d69646e69746538312f6c6f6f70792e7376673f6272616e63683d6d61696e)](https://travis-ci.com/midnite81/loopy) [![Coverage Status](https://camo.githubusercontent.com/33e1c2190132ceed50841f33974e34a1ffad115853d53268347f9b13111a3ef7/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d69646e69746538312f6c6f6f70792f62616467652e7376673f6272616e63683d6d61696e)](https://coveralls.io/github/midnite81/loopy?branch=main)

This is a PHP package which adds some namespaced array functions. Some of these functions can be natively accessed using array\_\* however there are few which aren't natively available.

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

[](#installation)

This package is available for PHP7.4+. To install use composer

```
composer require midnite81\loopy

```

Available Functions
-------------------

[](#available-functions)

- [each](#each)
- [all](#all)
- [some](#some)
- [map](#map)
- [reduce](#reduce)
- [filter](#filter)
- [times](#times)
- [once](#once)

Definitions
-----------

[](#definitions)

### each

[](#each)

`each(iterable $items, Closure $callback): void`

This function loops over each item. If the result of the closure returns false, then it will break the iteration at the point it returns false.

*Example*

```
use function Midnite81\Loopy\each;

$colours = [
    'blue',
    'red',
    'green',
    'yellow'
];

each($colours, function($colour, $key) {
    echo $colour . " is at index " . $key . "\n";
});
```

*Result*

```
blue is at index 0
red is at index 1
green is at index 2
yellow is at index 3
```

### all

[](#all)

`all(iterable $items, Closure $callback): bool`

This function checks to see if the result of the closure ($callback) is true for all iterations of the iterable passed ($items)

*Example*

```
use function Midnite81\Loopy\all;

$employees = [
    "id395" => ["name" => 'bob', "age" => 42, "dept" => 2],
    "id492" => ["name" => 'dave', "age" => 34, "dept" => 2],
    "id059" => ["name" => 'susan', "age" => 23, "dept" => 2],
];

$allBobs = all($employees, fn($employee) => $employee['name'] === 'bob');
// please note the key is also passed to the closure; therefore if the key is necessary
// to your function you could for example do the following
// $allBobs = all($employees, fn($employee, $key) => $employee['name'] === 'bob' && $key != 'id000');
```

*Result*

```
$allBobs = false;
// thankfully, not everyone in the department is called bob
```

### some

[](#some)

`some(iterable $items, Closure $callback): bool`

This function checks to see if the result of the closure ($callback) is true for one or more iterations of the iterable passed ($items)

*Example*

```
use function Midnite81\Loopy\some;

$employees = [
    "id395" => ["name" => 'bob', "age" => 42, "dept" => 2],
    "id492" => ["name" => 'dave', "age" => 34, "dept" => 2],
    "id059" => ["name" => 'susan', "age" => 23, "dept" => 2],
];

$allBobs = some($employees, fn($employee) => $employee['name'] === 'bob');

// please note the key is also passed to the closure; therefore if the key is necessary
// to your function you could for example do the following
// $allBobs = some($employees, fn($employee, $key) => $employee['name'] === 'bob' && $key != 'id000');
```

*Result*

```
$allBobs = true;
// one or more people in the department are called bob
```

### map

[](#map)

`map(iterable $items, Closure $callback): array`

*Example*

```
use function Midnite81\Loopy\map;

$employees = [
    "id395" => ["name" => 'bob', "age" => 42, "dept" => 2],
    "id492" => ["name" => 'dave', "age" => 34, "dept" => 2],
    "id059" => ["name" => 'susan', "age" => 23, "dept" => 2],
];

$allBobs = map($employees, fn($employee, $key) => $employee['name']');
```

*Result*

```
$allBobs = [
    'bob',
    'dave',
    'susan',
]
```

### reduce

[](#reduce)

`reduce(iterable $items, Closure $callback, string|int|float $initial = ""): string|int|float`

This function reduces down the values of an array to a single string, integer or float.

*Example*

```
use function Midnite81\Loopy\reduce;

$moneyReceived = [
    20.00,
    3.92,
    3.01,
    27.00
];

$totalMoneyReceived = reduce($moneyReceived, fn($current, $value, $key) => (float)$current + $value);
// $current is the current value of the reducer
```

*Result*

```
$totalMoneyReceived = 53.93;
```

### filter

[](#filter)

`filter(iterable $items, Closure $callback, bool $preserveKey = false): array`

This function filters down the iterable ($items) passed by only including what is true in the Closure ($callback). By default, the key is not preserved, but you can set it to true, if you wish to preserve the key.

*Example*

```
use function Midnite81\Loopy\filter;

$users = [
            ["name" => 'dave'],
            ["name" => 'susan'],
            ["name" => 'ingrid'],
            ["name" => 'patricia'],
            ["name" => 'sally'],
        ];

$usersWhoseNamesDontStartWithS = filter($users, fn($user) => !str_starts_with($user['name'], "s"));
```

*Result*

```
$usersWhoseNamesDontStartWithS = [
    'dave',
    'ingrid',
    'patricia'
]
```

### times

[](#times)

`times(iterable $items, Closure $callback, int $times): bool`

This function checks to see that the instance of the call back ($callback) should only be found the specified number of times in the iterable ($items)

*Example*

```
use function Midnite81\Loopy\times;

$peopleOnTheBus = [
    'andy',
    'bob',
    'sally',
    'wendy',
    'bob'
];

$areThereTwoBobsOnTheBus = times($peopleOnTheBus, fn($people) => $people === 'bob', 2);
```

*Result*

```
$areThereTwoBobsOnTheBus = true;
```

### once

[](#once)

`once(iterable $items, Closure $callback): bool`

Once is exactly the same as `times` however it will ensure the result of the closure only appears once in the iterable passed;

*Example*

```
use function Midnite81\Loopy\once;

$peopleOnTheBus = [
    'andy',
    'bob',
    'sally',
    'wendy'
];

$isThereJustOneAndyOnTheBus = once($peopleOnTheBus, fn($people) => $people === 'andy');
```

*Result*

```
$isThereJustOneAndyOnTheBus = true;
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Total

2

Last Release

1523d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/254850?v=4)[Simon Rogers](/maintainers/midnite81)[@midnite81](https://github.com/midnite81)

---

Top Contributors

[![midnite81](https://avatars.githubusercontent.com/u/254850?v=4)](https://github.com/midnite81 "midnite81 (13 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/midnite81-loopy/health.svg)

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

###  Alternatives

[aws/aws-sdk-php

AWS SDK for PHP - Use Amazon Web Services in your PHP project

6.3k543.5M2.6k](/packages/aws-aws-sdk-php)[guzzlehttp/guzzle

Guzzle is a PHP HTTP client library

23.5k1.0B35.4k](/packages/guzzlehttp-guzzle)[google/cloud-core

Google Cloud PHP shared dependency, providing functionality useful to all components.

346132.9M112](/packages/google-cloud-core)[toin0u/geocoder-laravel

Geocoder Service Provider for Laravel

7615.4M17](/packages/toin0u-geocoder-laravel)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21866.0M1.7k](/packages/drupal-core)

PHPackages © 2026

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