Codice PHP:
<?php
function array_2D_permute($items, $perms = array( )) {
static $permuted_array;
if (empty($items)) {
$permuted_array[]=$perms;
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
array_2D_permute($newitems, $newperms);
}
return $permuted_array;
}
}
$arr=array(6,8,0,1,1,1);
$result=array_2D_permute($arr);
echo "<pre>";
print_r($result);
echo "</pre>";
?>
Se cerchi su google ne trovi tanti di script che eseguono il calcolo delle permutazioni.