PHP code example of bentools / string-combinations

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

    

bentools / string-combinations example snippets



use function BenTools\StringCombinations\string_combinations;

foreach (string_combinations('abc') as $combination) { // Can also be string_combinations(['a', 'b', 'c'])
    echo $combination . PHP_EOL;
}

var_dump(string_combinations('abc')->asArray());

var_dump(count(string_combinations('abc'))); // 39

foreach (string_combinations('abc', $min = 2, $max = 2) as $combination) {
    echo $combination . PHP_EOL;
}

foreach (string_combinations(['woof', 'meow', 'roar'], 2, 3, '-') as $combination) {
    echo $combination . PHP_EOL;
}

$combinations = string_combinations('abc');
var_dump(count($combinations)); // 39
print_r($combinations->asArray());

$combinations = $combinations->withoutDuplicates();
var_dump(count($combinations)); // 15
print_r($combinations->asArray());


use function BenTools\StringCombinations\string_combinations;

$start = microtime(true);
$combinations = string_combinations('abcd1234');
foreach ($combinations as $c => $combination) {
    continue;
}
$end = microtime(true);

printf(
    'Generated %d combinations in %ss - Memory usage: %sMB / Peak usage: %sMB' . PHP_EOL,
    ++$c,
    round($end - $start, 3),
    round(memory_get_usage(true) / 1024 / 1024),
    round(memory_get_peak_usage(true) / 1024 / 1024)
);