domwebber/array-toggle-permutations

PHP 数组排列迭代器。一种简单的方法来遍历数组中所有可能的项目组合。

v1.0.2 2021-07-12 21:55 UTC

This package is auto-updated.

Last update: 2024-09-13 04:52:26 UTC


README

PRs Welcome Latest Stable Version Total Downloads License

一个有用的PHP工具,可以轻松遍历数组中所有可能的项目组合。此包旨在用于测试环境,但经过单元测试,因此也适合在生产环境中使用(在合理范围内)。

安装

使用 composer 包管理器安装数组排列迭代器。

composer require domwebber/array-toggle-permutations

用法

此库可用于切换数字索引数组和关联数组的选项。在使用关联数组的情况下,数组键将保持不变。在任何情况下,数组项都将保持原始顺序。

基本用法

use Dw\Utils\ArrayTogglePermutations;

$iterator = new ArrayTogglePermutations(
    [0,1,2]
);

// $iterator = new ArrayTogglePermutations(...);
foreach ($iterator as $permutation) {
    // Do something with the combination... For example:
    var_dump($permutation);
}

请参阅 示例

贡献

请参阅 变更日志

文件签名

wherever possible, files should include a file signature comment.

/**
 * PHP Array Permutations Iterator.
 *
 * @since 1.0.0
 * @package Dw\Utils
 * @copyright 2021 Dom Webber <dom.webber@hotmail.com>
 * @link https://github.com/domwebber
 */

许可证

GNU GPL v3.0

© 2021 Dom Webber