I saw this function (Get all permutations of a PHP array?), but i can't understand on how some of these coding works, can help to explain? I am new in php by the way.
Here's the code:
function pc_permute($items, $perms = array())
{
if (empty($items))
{
echo join(' ', $perms) . "<br />";
}
else
{
for ($i = count($items) - 1; $i >= 0; --$i)
{
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
pc_permute($newitems, $newperms);
}
}
}
$arr = array('peter', 'paul', 'mary');
pc_permute($arr);
why uselist($foo)
? I tried to use array, it doesn't work(I don't understand list)
And why use array_unshift($newperms, $foo);
? for what? Sorry, I really new in php T.T