Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

PatchRanger/cartesian-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

27 Commits

Repository files navigation

cartesian-iterator

Iterator, returning the cartesian product of associative array of iterators. See https://en.wikipedia.org/wiki/Cartesian_product .

Alternative implementations

Benchmark

https://github.com/PatchRanger/php-cartesian-benchmark

Quickstart

<?php
use PatchRanger\CartesianIterator;
require 'vendor/autoload.php';
$cartesianIterator = new CartesianIterator();
// The second argument controls the key of the corresponding value in the product array.
$cartesianIterator->attachIterator(new ArrayIterator([1,2]), 'test');
// No second argument means incremental numeration (indexed).
$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
 )
)

About

Iterator, returning the cartesian product of associative array of iterators. See https://en.wikipedia.org/wiki/Cartesian_product .

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

Languages

AltStyle によって変換されたページ (->オリジナル) /