Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php中没有重复的有序组合?_Php_Combinations - Fatal编程技术网

php中没有重复的有序组合?

php中没有重复的有序组合?,php,combinations,Php,Combinations,我有以下数组: 数组(“一”、“二”、“三”、“四”) 我需要一个函数,可以输出数组元素的所有有序组合,而不需要重复。输出应该是 one one two one two three one two three four two two three two three four three three four four 输出不应包括: one one one two four two one three four two three 等等 你们中有人已经实现了这种alghoritm吗?这将只

我有以下数组:

数组(“一”、“二”、“三”、“四”)

我需要一个函数,可以输出数组元素的所有有序组合,而不需要重复。输出应该是

one
one two
one two three
one two three four
two
two three
two three four
three
three four
four
输出不应包括:

one one
one two four
two one three
four two three
等等


你们中有人已经实现了这种alghoritm吗?

这将只是两个嵌套循环:


你试过什么吗?这似乎很简单。我在网上搜索了各种解决方案,但我发现的都是有/没有重复的排列,不适合我的需要
function permutation(array $arr)
{
    while($ele=array_shift($arr))
    {
        $x=$ele;
        echo $x."\n";
        foreach($arr as $rest)
        {
            $x.=" $rest";
            echo $x."\n";
        }
    }
}
permutation(array("one","two","three","four"));