phpOMS/Utils/Permutation.php
Scrutinizer Auto-Fixer 114ce12de8 Scrutinizer Auto-Fixes
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
2016-03-28 14:44:47 +00:00

28 lines
645 B
PHP

<?php
namespace phpOMS\Utils;
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;
}
}