mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-13 18:48:40 +00:00
This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com
28 lines
650 B
PHP
28 lines
650 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;
|
|
}
|
|
} |