ahungry / powerset
生成多维数组的幂集(枚举所有可能的值)
0.2.0
2018-02-06 02:08 UTC
This package is not auto-updated.
Last update: 2024-09-21 11:24:17 UTC
README
这是一个PHP包,允许您生成多维数组的幂集(枚举所有可能的值)。
安装
关注此包在Packagist上的可用性,届时您可以使用以下命令安装(更新:它现在在Packagist上了!)
composer require ahungry/powerset
但在此期间,要安装,请通过以下方式克隆仓库
git clone https://github.com/ahungry/ahungry-powerset.git
并包含文件,或者在你的composer.json中添加一个新的VCS引用,如下所示
"repositories": [ { "type": "vcs", "url": "https://github.com/ahungry/ahungry-powerset" } ], "require": { "ahungry/powerset": "^0.1" }
然后执行以下命令
composer update
使用ahungry-powerset
在require它(或使用composer自动加载)之后,您可以通过以下方式使用它(请参阅blub.php以获取示例)
use Com\Ahungry\Powerset\Functions as pset; $b = [[ 'a' => [1,2], 'b' => [3,4], ]]; pset\powerSet($b); print_r($b);
这将产生以下输出
Array ( [0] => Array ( [a] => 2 [b] => 4 ) [1] => Array ( [a] => 2 [b] => 3 ) [2] => Array ( [a] => 1 [b] => 4 ) [3] => Array ( [a] => 1 [b] => 3 ) )
哦,它还可以与嵌套数组一起工作
$a = [[ 'a' => 0, 'x' => [ ['b' => 1, 'c' => ['a', 'b', 'c']], ['b' => 3, 'c' => ['a', 'b', 'c']], ['b' => 5, 'c' => ['a', 'b', 'c']], ], 'y' => [7, 8, 9], ]]; ps\powerSet($a); $this->assertCount(27, $a); // true
待办事项
-
将包列在Packagist上
-
生成真正的幂集(包括空值可能性)
许可
GPLv3