第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

關(guān)于PHP數(shù)組組合

關(guān)于PHP數(shù)組組合

PHP
慕標(biāo)琳琳 2019-08-03 12:03:38
PHP數(shù)組組合我有一個(gè)由7個(gè)數(shù)字組成的數(shù)組(1,2,3,4,5,6,7),我想對(duì)5個(gè)數(shù)字,如(1,2,3,4,5),(1,2,3,4,6),(1,2,3,4,7)(1,2,3,4,5)等于(4,5,3,1,2)我想知道PHP中是否有一個(gè)函數(shù)或任何算法可以做到這一點(diǎn)?我不知道從哪里開(kāi)始。你能幫我嗎?我想把7個(gè)給定數(shù)字的組合(它們是從一個(gè)數(shù)組中取出來(lái)的)放到5個(gè)插槽中,而不考慮順序。
查看完整描述

3 回答

?
吃雞游戲

TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊

<?php

echo "<pre>";$test = array("test_1","test_2","test_3");// Get Combination$return = uniqueCombination($test);//Sortsort($return);//Pretty Printprint_r(array_map(function($v){ return implode(",", $v); }, $return));function uniqueCombination($in, $minLength = 1, $max = 2000) {
    $count = count($in);
    $members = pow(2, $count);
    $return = array();
    for($i = 0; $i < $members; $i ++) {
        $b = sprintf("%0" . $count . "b", $i);
        $out = array();
        for($j = 0; $j < $count; $j ++) {
            $b{$j} == '1' and $out[] = $in[$j];
        }

        count($out) >= $minLength && count($out) <= $max and $return[] = $out;
        }
    return $return;}?>

輸出量

Array

(

    [0] => test_1

    [1] => test_2

    [2] => test_3

    [3] => test_1,test_2

    [4] => test_1,test_3

    [5] => test_2,test_3

    [6] => test_1,test_2,test_3

)



查看完整回答
反對(duì) 回復(fù) 2019-08-04
?
慕斯709654

TA貢獻(xiàn)1840條經(jīng)驗(yàn) 獲得超5個(gè)贊

這個(gè)Math_Combinatorics在PEAR存儲(chǔ)庫(kù)中,您想做什么就做什么:

返回所有組合和排列的包,不重復(fù)、給定集和子集的大小。關(guān)聯(lián)數(shù)組被保留。


require_once 'Math/Combinatorics.php';

$combinatorics = new Math_Combinatorics;


$input = array(1, 2, 3, 4, 5, 6, 7);

$output = $combinatorics->combinations($input, 5); // 5 is the subset size


// 1,2,3,4,5

// 1,2,3,4,6

// 1,2,3,4,7

// 1,2,3,5,6

// 1,2,3,5,7

// 1,2,3,6,7

// 1,2,4,5,6

// 1,2,4,5,7

// 1,2,4,6,7

// 1,2,5,6,7

// 1,3,4,5,6

// 1,3,4,5,7

// 1,3,4,6,7

// 1,3,5,6,7

// 1,4,5,6,7

// 2,3,4,5,6

// 2,3,4,5,7

// 2,3,4,6,7

// 2,3,5,6,7

// 2,4,5,6,7

// 3,4,5,6,7



查看完整回答
反對(duì) 回復(fù) 2019-08-04
  • 3 回答
  • 0 關(guān)注
  • 310 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)