Can somenone help me to find what is wrong in this code where it will generate only 3 element combinations instead of 4.
function pc_permute($items, $perms = array( )) {
$back = array();
if (empty($items)) {
$back[] = join(' ', $perms);
} else {
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
$back = array_merge($back, pc_permute($newitems, $newperms));
}
}
return $back;
}
var_dump(pc_permute(array('123','124','312','555')));
this code output combinations of this 4 elements of array.(e.g. ('123',312','124','555') What I need is to output combinations of 3 elements from this 4 (e.g. ('123','312','124') ('123','124,'555') ..... etc
Please don't mark this as duplicate as the other thread has only a permutation but didn't satisfy my conditions.
PHP or Javascript code will do. Thanks!