Here is the original function (recursive function):
function permute($items, $perms = array())
{
if (empty($items))
{
echo join('', $perms).'<br>';
}
else
{
for ($i = 0; $i < count($items); ++$i)
{
$newitems = $items;
$newperms = $perms;
$foo = implode(array_splice($newitems, $i, 1));
array_unshift($newperms, $foo);
permute($newitems, $newperms);
}
}
}
permute(array("A", 'B', 'C'));
In this case, the output will be:
cba
bca
cab
acb
bac
abc
How to modify this part:
if (empty($items))
{
echo join('', $perms).'<br>';
}
change it to return array of string instead of directly echo in the function?