mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
All these files need further edits + other optimization files + moving of files
24 lines
603 B
PHP
24 lines
603 B
PHP
<?php
|
|
|
|
class Permutation
|
|
{
|
|
// usage: permut(['a', 'b', 'c']);
|
|
public static function permut(array $toPermute, array $result = []) : array
|
|
{
|
|
$permutations = [];
|
|
|
|
if(empty($toPermute)){
|
|
$permutations[] = implode("", $result);
|
|
}else{
|
|
foreach($toPermute as $key => $val){
|
|
$newArr = $toPermute;
|
|
$newres = $result;
|
|
$newres[] = $val;
|
|
unset($newArr[$key]);
|
|
$permutations += permut($newArr, $newres);
|
|
}
|
|
}
|
|
|
|
return $permutations;
|
|
}
|
|
} |