PHP code example of blibio / combinatorics

1. Go to this page and download the library: Download blibio/combinatorics library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

blibio / combinatorics example snippets




declare(strict_types=1);

use Blibio\Combinatorics\Combinatorics;

$elements = ['A', 'B', 'C', 'D'];
$k = 3;

// Using the boolean parameter:
$it = Combinatorics::combinations($elements, $k, withRepetition: false);

// or:
// $it = Combinatorics::combinations($elements, $k, withRepetition: true);
// $it = Combinatorics::permutations($elements, $k, withRepetition: false);
// $it = Combinatorics::permutations($elements, $k, withRepetition: true);

// Using the explicit method names:
// $it = Combinatorics::combinationsWithoutRepetition($elements, $k);
// $it = Combinatorics::combinationsWithRepetition($elements, $k);
// $it = Combinatorics::permutationsWithoutRepetition($elements, $k);
// $it = Combinatorics::permutationsWithRepetition($elements, $k);

foreach ($it as $set) {
    // use $set
}