PHP code example of kevinsimard / combinatorics

1. Go to this page and download the library: Download kevinsimard/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/ */

    

kevinsimard / combinatorics example snippets


$instance = new Combinatorics(["foo", "bar"]);

$instance->add("baz");
$instance->add("qux");

// ["foo", "bar", "baz", "qux"]

$instance = new Combinatorics(["foo", "bar"]);

$instance->reset();

// []


$elements = ["foo", "bar", "baz"];

$instance = new Combinatorics($elements);
foreach ($instance->permutations() as $value) {
    ...
}

// OR

foreach (Combinatorics::permutations($elements) as $value) {
    ...
}

// [
//     ["foo", "bar", "baz"],
//     ["bar", "foo", "baz"],
//     ["bar", "baz", "foo"],
//     ["foo", "baz", "bar"],
//     ["baz", "foo", "bar"],
//     ["baz", "bar", "foo"]
// ]