Skip to content

Instantly share code, notes, and snippets.

@dashmug
Created June 17, 2013 20:58
Show Gist options
  • Save dashmug/5800353 to your computer and use it in GitHub Desktop.
Save dashmug/5800353 to your computer and use it in GitHub Desktop.
A package that returns all the combinations and permutations, without repitition, of a given set and subset size. Associative arrays are preserved. Download from: http://pear.php.net/package/Math_Combinatorics/download
require_once 'Math/Combinatorics.php';
$combinatorics = new Math_Combinatorics;
var_dump($combinatorics->combinations(array(
'one' => 'a',
'two' => 'b',
'three' => 'c',
'four' => 'd',
), 3));
require_once 'Math/Combinatorics.php';
$combinatorics = new Math_Combinatorics;
var_dump($combinatorics->permutations(array(
'one' => 'a',
'two' => 'b',
'three' => 'c',
'four' => 'd',
), 3));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment