使用php构建概率树?

Hai*_*ood 5 php tree probability

可能重复:
排列 - 所有可能的数字集

我有一个包含选项列表的数组,每个选项都是唯一的,不能重复.

我想使用以下选项构建概率树:

$options = array('1','2','3','4','A','E','I','O');
Run Code Online (Sandbox Code Playgroud)

所以一条有效的线可能是 1-2-E-3-O-I-4-A

我怎样才能做到这一点?(或者至少指出我正确的方向!)

Peo*_*eon 0

<?php

function pc_permute($items, $perms = array( )) {
    if (empty($items)) { 
        print join('-', $perms) . "<br />";
    }  else {
        for ($i = count($items) - 1; $i >= 0; --$i) {
            $newitems = $items;
            $newperms = $perms;
            list($foo) = array_splice($newitems, $i, 1);
            array_unshift($newperms, $foo);
            pc_permute($newitems, $newperms);
        }
    }
}

$options = array( '1','2','3','4','A','E','I','O' );
$mass = pc_permute( $options );

?>
Run Code Online (Sandbox Code Playgroud)