例如这是我的文字:
$str = 'buy new microsoft windows';@H_403_3@我用数组爆炸文本和列表:
Array ( [0] => buy [1] => new [2] => microsoft [3] => windows )@H_403_3@我想在数组中生成如下所示的内容:
buy new buy new windows buy microsoft buy microsoft windows buy windows new microsoft new microsoft windows new windows microsoft windows@H_403_3@我用foreach和rand尝试,但我不能像显示那样生成.有没有机会像我的要求一样产生?
你可以看看这个
PEAR PACKAGE
使用示例
使用示例
<?PHP require_once 'Math/Combinatorics.PHP'; $words = array('buy','new','microsoft'); $combinatorics = new Math_Combinatorics; foreach($combinatorics->permutations($words,2) as $p) { echo join(' ',$p),"\n"; }@H_403_3@输出结果为:
buy new new buy buy microsoft microsoft buy new microsoft microsoft new