Php 是否将数组值推送到每一个其他数组值?
我不太确定如何解释我的问题 我有这样的数组Php 是否将数组值推送到每一个其他数组值?,php,arrays,Php,Arrays,我不太确定如何解释我的问题 我有这样的数组 $foo = array{"one", "two", "three"} 我需要把每一个值推到另一个值 需要这样的结果 $new = array{"one two three", "one two", "one three", "two three", "one", "two", "three"} 这样的结果有可能吗 我希望有人能帮助我 之前谢谢:)您似乎正在寻找一个功率集,这里是一个指向算法的链接:这里是对您的问题的一个相当简单的尝试 <?p
$foo = array{"one", "two", "three"}
我需要把每一个值推到另一个值
需要这样的结果
$new = array{"one two three", "one two", "one three", "two three", "one", "two", "three"}
这样的结果有可能吗
我希望有人能帮助我
之前谢谢:)您似乎正在寻找一个功率集,这里是一个指向算法的链接:这里是对您的问题的一个相当简单的尝试
<?php
function perms($array) {
$res = array( array() );
foreach ($array as $val) {
$n = count($res);
for($i=0; $i < $n; $i++) {
$res[] = array_merge( array($val), $res[$i] );
}
}
return $res;
}
$array = array("one", "two", "three");
print_r( perms($array) );
哦,天哪,这太复杂了>。