I have a function that finds all the possible combinations of an array:
function combination($array)
{
$results = array(array());
foreach ($array as $element)
foreach ($results as $combination)
array_push($results, array_merge(array($element), $combination));
return $results;
}
This returns a multidimensional array and it works.
If I try to print the array, I use this:
foreach (combination($set) as $combination)
{
print join("\t", $combination) . " - ";
}
For: $set = array('s','f','g');
The output is: - s - f - f s - g - g s - g f - g f s -
Now what I cant figure out is how can I sort the combinations according to length in a way where the output becomes: - g f s - g s - g f - f s - g - s - f -