Php 字符串的渐进式单词组合

Php 字符串的渐进式单词组合,php,algorithm,string,factorial,Php,Algorithm,String,Factorial,我需要获得一个字符串的渐进式单词组合 例如,“这是字符串” 输出:“这是字符串” “这是” “此字符串” “是字符串” “这个” “是” “字符串” 你知道类似的算法吗?(我需要php语言) 谢谢;) 查看算法说明。这是解决问题的简单代码。 我将每个字符串重新连接到数组中的其余字符串 $string = "this is a string"; $strings = explode(' ', $string); // print result print_r(concat($strings,

我需要获得一个字符串的渐进式单词组合

例如,“这是字符串” 输出:“这是字符串” “这是” “此字符串” “是字符串” “这个” “是” “字符串”

你知道类似的算法吗?(我需要php语言)
谢谢;)

查看算法说明。

这是解决问题的简单代码。 我将每个字符串重新连接到数组中的其余字符串

$string = "this is a string";  
$strings = explode(' ', $string);

// print result
print_r(concat($strings, ""));

// delivers result as array
function concat(array $array, $base_string) {

    $results = array();
    $count = count($array);
    $b = 0;
    foreach ($array as $key => $elem){
        $new_string = $base_string . " " . $elem;
        $results[] = $new_string;
        $new_array = $array;

        unset($new_array[$key]);

        $results = array_merge($results, concat ($new_array, $new_string));

    }
    return $results;
}

谢谢你的支持。我需要逐步改变字数,而不仅仅是简单的排列。例如(“1 2 3”)输出(“123”、“12”、“13”、“23”、“1”、“2”、“3”),然后只需将该算法与生成所有组合的另一个算法组合即可:)这是我的问题:D。我不知道产生所有组合的算法:D这正是我要找的。你救了我的命:D.谢谢。很高兴能帮上忙