enjoys / cartesian-iterator
Cartesian Iterator
Installs: 2 349
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
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: 2024-10-29 08:57:53 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
)
)