enjoys/cartesian-iterator

Cartesian Iterator

0.1.1 2023-08-29 06:14 UTC

This package is auto-updated.

Last update: 2024-10-29 08:57:53 UTC


README

Tests Scrutinizer Code Quality Code Coverage Mutation testing badge psalm

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
        )

)