标签:++ slice hit tmp array ati result nbsp this
class a
{
public $fullPermutationArr = array();
public function fullPermutation($arr, $str = ‘‘)
{
$cnt = count($arr);
if ($cnt == 1) {
array_push($this->fullPermutationArr, $str ? $str . ‘,‘ . $arr[0] : $arr[0]);
} else {
for ($i = 0; $i < $cnt; $i++) {
$tmp = $arr[0];
$arr[0] = $arr[$i];
$arr[$i] = $tmp;
$this->fullPermutation(array_slice($arr, 1), $str ? $str . ‘,‘ . $arr[0] : $arr[0]);
}
}
}
public function unique($result)
{
return array_merge(array_unique($result));
}
}
// 调用
$a = new a;
$a->fullPermutation([1, 2,2]);
$result = $a->fullPermutationArr;
var_dump($a->unique($result));
php 全排列
标签:++ slice hit tmp array ati result nbsp this
原文地址:https://www.cnblogs.com/zhangxuedonga/p/9829550.html