承接 fabis94/php-twiddle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fabis94/php-twiddle

Composer 安装命令:

composer require fabis94/php-twiddle

包简介

The Chase's Twiddle algorithm rewritten in PHP that returns all combinations of m out of n objects.

README 文档

README

Chase's Twiddle algorithm for returning all m-combinations of an array of size n. More info about the original algorithm can be found here and a C implementation can be found here.

Unlike other recursive algorithms for building combinations this one allows you to build combinations iteratively and thus stop at any point when you've had enough without having to build all of the combinations first. This package provides both a PHP \Generator and a standard method for retrieving

Requirements

PHP7.4 & PHP8

How to use

The following code will initialize a new Twiddle instance for building 2-combinations of a set of size 10.

$setSize = 10;
$combinationSize = 2;
$twiddle = new Twiddle($setSize, $combinationSize);

After initializing the instance you can run the algorithm on all arrays of size n (10 in the example).

// Get all possible combinations
$values = [1,2,3,4,5,6,7,8,9,0]
$allCombinations = $twiddle->getAllCombinations($values);

// Get first three combinations
$values = ['a','b','c','d','e','f','g','h','j','k']
$combinationGenerator = $twiddle->getCombinationGenerator($values);
$firstThree = [];
$i = 0;
foreach ($combinationGenerator as $combination) {
    if ($i >= 3) break;
    
    $firstThree[] = $combination;
    $i++;
}

Local development

Run docker-compose up -d to run the docker environment. You can then SSH into one of the PHP containers (one has php7.4 and the other one has php8.0) to run composer, tests etc.: docker-compose exec php7 bash or docker-compose exec php8 bash

The codebase is going to be mounted onto /app inside the containers.

Run tests inside container with composer test.

统计信息

  • 总下载量: 56.71k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-08-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固