enjoys / cartesian-iterator
Cartesian Iterator
Installs: 4 542
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/enjoys/cartesian-iterator
Requires
- php: ^7.3 | ^8.0
Requires (Dev)
- infection/infection: ~0.18
- phpunit/phpunit: ^9.0
- symfony/var-dumper: ^5.4 | ^6.0
- vimeo/psalm: ^4.0
This package is auto-updated.
Last update: 2025-10-29 03:34:04 UTC
README
Cartesian Iterator
Fork https://github.com/PatchRanger/cartesian-iterator
Iterator, returning the cartesian product of associative array of iterators. See https://en.wikipedia.org/wiki/Cartesian_product .
<?php $cartesianIterator = new \Enjoys\CartesianIterator(); $cartesianIterator->attachIterator(new \ArrayIterator([1,2]), 'test'); $cartesianIterator->attachIterator(new \ArrayIterator(['foo', 'bar'])); $result = iterator_to_array($cartesianIterator, false); print_r($result);
Result:
Array
(
    [0] => Array
        (
            [test] => 1
            [1] => foo
        )
    [1] => Array
        (
            [test] => 2
            [1] => foo
        )
    [2] => Array
        (
            [test] => 1
            [1] => bar
        )
    [3] => Array
        (
            [test] => 2
            [1] => bar
        )
)