patchranger/cartesian-iterator
最新稳定版本:0.07
Composer 安装命令:
composer require patchranger/cartesian-iterator
包简介
Cartesian iterator
README 文档
README
Iterator, returning the cartesian product of associative array of iterators. See https://en.wikipedia.org/wiki/Cartesian_product .
Alternative implementations
- https://github.com/phpbench/phpbench/blob/master/lib/Benchmark/CartesianParameterIterator.php : A little bit more messy.
- https://github.com/bpolaszek/cartesian-product : Not so laconic - but covered by tests.
- https://stackoverflow.com/a/15973172 : Pretty simple though no iterator, plain array-stuff.
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
)
)
统计信息
- 总下载量: 10.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2018-11-11