PHPackages                             phpexperts/combinatorics - 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. phpexperts/combinatorics

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

phpexperts/combinatorics
========================

A collection of utility classes for dealing with combinations.

v1.1.1(5y ago)91881[1 PRs](https://github.com/phpexpertsinc/Combinatorics/pulls)1MITPHPPHP &gt;=7.1CI failing

Since Jun 15Pushed 5y ago1 watchersCompare

[ Source](https://github.com/phpexpertsinc/Combinatorics)[ Packagist](https://packagist.org/packages/phpexperts/combinatorics)[ Docs](https://www.phpexperts.pro/)[ RSS](/packages/phpexperts-combinatorics/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (4)Used By (1)

Combinatorics
=============

[](#combinatorics)

[![TravisCI](https://camo.githubusercontent.com/fe7e9790c961befaaa821e3072b0bf522d06b8ef0a4e357d8ffb0163489b6aa4/68747470733a2f2f7472617669732d63692e6f72672f70687065787065727473696e632f436f6d62696e61746f726963732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpexpertsinc/Combinatorics)[![Maintainability](https://camo.githubusercontent.com/3cb94f70cedf0bc397fb4f8fe17a6f4f4cbc8b323961f27c4caff6fda0d30ff1/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f63623630376465383239326564356232303861652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/phpexpertsinc/Combinatorics/maintainability)[![Test Coverage](https://camo.githubusercontent.com/f0bb51469236b3a06484a9546c02e9f248e738159545d0dc6c3fba9b7039d165/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f63623630376465383239326564356232303861652f746573745f636f766572616765)](https://codeclimate.com/github/phpexpertsinc/Combinatorics/test_coverage)

Combinatorics is a PHP Experts, Inc., Project meant for the ease of access of Combinatorics algorithms.

See

### Memory Consumption

[](#memory-consumption)

Storing thousands of possibilities can be extremely memory intensive.

However, this project utilizes PHP Generators and uses only a few kilobytes to calculate and output millions of potential combinations (See the **Benchmarks** section below).

### Generating All Possible Combinations

[](#generating-all-possible-combinations)

What are all the possibilities of A, B, C and D? More than you might think! 64. Add two more letters and you've got 1,956 possibilities.

How many different parking spot orderings can 8 cars occupy on any given day? Find out in the **Usage** section below!

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

[](#installation)

Via Composer

```
composer require phpexperts/combinatorics
```

Usage
-----

[](#usage)

```
$generator = new CombinationsGenerator();

foreach ($generator->generate($styles) as $combination) {
    // If you can do what you need to do with the combinations here, without immediately storing
    // them into an array, then your memory usage will never exceed the amount needed store one
    // combination.
}
```

You can see real-world usage of this project in the test suite of the **Console Painter project**\]().

Use cases
---------

[](#use-cases)

Testing
-------

[](#testing)

```
phpunit --testdox
```

To actually see what's going on -and- run the stress tests, run

```
phpunit --debug
```

Note: It takes over 5 minutes on an Intel i7 to run all of the stress tests.

Benchmarks
----------

[](#benchmarks)

```
Level 1: Generating combinations for A
[
  Number of possibilities => 2
  Time (ms)               => 0.051975250244141
  Time (s)                => 5.1975250244141E-5
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 2: Generating combinations for A, B
[
  Number of possibilities => 4
  Time (ms)               => 0.047922134399414
  Time (s)                => 4.7922134399414E-5
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 3: Generating combinations for A, B, C
[
  Number of possibilities => 15
  Time (ms)               => 0.22578239440918
  Time (s)                => 0.00022578239440918
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 4: Generating combinations for A, B, C, D
[
  Number of possibilities => 64
  Time (ms)               => 1.0910034179688
  Time (s)                => 0.0010910034179688
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 5: Generating combinations for A, B, C, D, E
[
  Number of possibilities => 325
  Time (ms)               => 6.5748691558838
  Time (s)                => 0.0065748691558838
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 6: Generating combinations for A, B, C, D, E, F
[
  Number of possibilities => 1956
  Time (ms)               => 47.721147537231
  Time (s)                => 0.047721147537231
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 7: Generating combinations for A, B, C, D, E, F, G
[
  Number of possibilities => 13699
  Time (ms)               => 395.29585838318
  Time (s)                => 0.39529585838318
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 8: Generating combinations for A, B, C, D, E, F, G, H
[
  Number of possibilities => 109600
  Time (ms)               => 3834.4430923462
  Time (s)                => 3.8344430923462
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
Level 9: Generating combinations for A, B, C, D, E, F, G, H, I
[
  Number of possibilities => 986409
  Time (ms)               => 37884.353876114
  Time (s)                => 37.884353876114
  Memory consumed         => 320
  Peak Memory (Diff)      => 0
]
Level 10: Generating combinations for A, B, C, D, E, F, G, H, I, J
[
  Number of possibilities => 9864100
  Time (ms)               => 422606.03785515
  Time (s)                => 422.60603785515
  Memory consumed         => 0
  Peak Memory (Diff)      => 0
]
```

Contributors
------------

[](#contributors)

[Theodore R. Smith](https://www.phpexperts.pro/%5D)
GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
CEO: PHP Experts, Inc.

{ "transactionId" : "$transactionId", "crmId" : "$crmId", "zAccountId" : "$zuoraAccountId", "facilityId" : "$facilityId", "promo\_code" : "$promo\_code", "transactionTotal" : "$total\_cost\_for\_facebook", "transactionProducts" : \[$transactionProducts\], "transactionAffiliation" : "U.S. LawShield" }

License
-------

[](#license)

MIT license. Please see the [license file](LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

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

Total

3

Last Release

1870d ago

PHP version history (2 changes)v1.0.0PHP ^7.1

v1.1.0PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f3a2dd16766f6b03c330e65aaca9dfb97f1bbbb41c5e2af5681f58f670b7917?d=identicon)[hopeseekr](/maintainers/hopeseekr)

---

Top Contributors

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

---

Tags

algorithmcombinationscombinatoricsphpcombinatoricscombinations

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpexperts-combinatorics/health.svg)

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

###  Alternatives

[markrogoyski/math-php

Math Library for PHP. Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra

2.4k7.1M40](/packages/markrogoyski-math-php)[alphazygma/combinatorics

Math libraries for Combinatorics (Combinations, Permutations, ...).

15192.0k](/packages/alphazygma-combinatorics)

PHPackages © 2026

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