I\'ve looked everywhere for this online, but couldn\'t completely find it. (my PHP and math skills are letting my down for this one...) I have an array containing for exampl
As always, it's much more fun to solve the problem your own way. You can modify your code to fit your special needs much easier then, because you know what you are doing :) See my test script below:
$a = array("a", "b", "c");
function getAll($prefix, $remaining)
{
echo $prefix."\n";
if (count($remaining) == 0) return;
if (count($remaining) == 1)
{
echo $prefix.$remaining[0]."\n";
return;
}
for ($i = 0; $i < count($remaining); $i++)
{
$t = $remaining;
unset($t[$i]);
$t = array_values($t);
getAll($prefix.$remaining[$i], $t);
}
}
echo "\n";
getAll('', $a);
echo "
\n";
?>
I just echo'd the intended output, you could add up a result array instead, but that's your part :)
Output:
[] //empty value is included, but blank lines won't show up here, so I wrote []
a
ab
abc
ac
acb
b
ba
bac
bc
bca
c
ca
cab
cb
cba