domwebber / array-toggle-permutations
PHP array permutations iterator. A simple way to loop through every possible combination of items in an array.
Requires
- markrogoyski/math-php: ^2.2
Requires (Dev)
- phpstan/phpstan: ^0.12.92
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
- vimeo/psalm: ^4.8
This package is auto-updated.
Last update: 2024-11-13 05:21:20 UTC
README
A helpful PHP utility that easily loops through every possible combination of array items. This package is intended for use in testing environments but is unit tested to the degree that it is also safe for use in a production environment too (within reason).
Installation
Use the composer package manager to install the Array Permutations Iterator.
composer require domwebber/array-toggle-permutations
Usage
This library can be used to toggle the options of a numerically-indexed array or an associative array. In the case where an associative array is used, the array keys will be maintained. In either case, the array items will stay in the original order.
Basic usage:
use Dw\Utils\ArrayTogglePermutations; $iterator = new ArrayTogglePermutations( [0,1,2] ); // $iterator = new ArrayTogglePermutations(...); foreach ($iterator as $permutation) { // Do something with the combination... For example: var_dump($permutation); }
See examples.
Contributing
See the changelog.
File Signatures
Wherever possible, files should include a file signature comment.
/** * PHP Array Permutations Iterator. * * @since 1.0.0 * @package Dw\Utils * @copyright 2021 Dom Webber <dom.webber@hotmail.com> * @link https://github.com/domwebber */
License
© 2021 Dom Webber