【发布时间】:2012-06-01 15:16:38
【问题描述】:
我有一个函数可以找到数组的所有可能组合:
function combination($array)
{
$results = array(array());
foreach ($array as $element)
foreach ($results as $combination)
array_push($results, array_merge(array($element), $combination));
return $results;
}
这会返回一个多维数组并且它可以工作。
如果我尝试打印数组,我会使用这个:
foreach (combination($set) as $combination)
{
print join("\t", $combination) . " - ";
}
发给:$set = array('s','f','g');
输出为:- s - f - f s - g - g s - g f - g f s -
现在我想不通的是如何根据长度对组合进行排序,输出变为:- g f s - g s - g f - f s - g - s - f -
【问题讨论】:
-
看看这个链接...stackoverflow.com/questions/838227/…