lunkkun/permutations-generator

A PHP Generator that generates all possible permutations for a given array of values.

Maintainers

Package info

github.com/lunkkun/php-permutations-generator

pkg:composer/lunkkun/permutations-generator

Statistics

Installs: 118

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v2.0.0 2019-10-29 14:33 UTC

This package is auto-updated.

Last update: 2026-03-01 00:29:31 UTC


README

Summary

A PHP Generator that generates all possible permutations for a given array of values.

Important note

I've optimized the code for performance. Therefore, the order in which the permutations are generated, might differ from what you might expect. To get the permutations in ascending order, you can reverse() every result you get from the generator.

Installation

With composer:

composer require lunkkun/permutations-generator

Usage

<?php

$array = range(0, 2);
$generator = new \Lunkkun\PermutationsGenerator\PermutationsGenerator($array);

foreach ($generator as $permutation) {
    print_r($permutation);
}

License

PHP Permutations Generator is open-sourced software licensed under the MIT license.