文字列のプログレッシブ単語の組み合わせを取得する必要があります。
例:「thisisstring」出力:「thisisstring」「thisis」「thisstring」「isstring」「this」「is」「string」
同様のアルゴリズムを知っていますか?(私は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;
}
例をチェックしてください。アルゴリズムの説明については、http://en.wikipedia.org/wiki/Permutation#Systematic_generation_of_all_permutationsを参照してください。