I want the combination of the number 1 to nth.
Example sets:
Number Range: 1,2,3
Combination of output in 2 digits ( if number range is 1 to 4 then I want it in 2 or 4 digit. So it's dynamic base on the number range)
Output:
1,2
1,3
2,3
3,1
etc...
If Combination of output in 3 digits
Output:
1,2,3
2,1,3
1,3,2
3,1,2
2,3,1
3,2,1
etc...
I have tried below function for the combination but I want it in 2 digit
function pc_permute($items, $perms = array( )) {
if (empty($items)) {
$return = array($perms);
} else {
$return = array();
for ($i = count($items) - 1; $i >= 0; --$i) {
$newitems = $items;
$newperms = $perms;
list($foo) = array_splice($newitems, $i, 1);
array_unshift($newperms, $foo);
$return = array_merge($return, pc_permute($newitems, $newperms));
}
}
return $return;
}
echo "<br> <pre>";
$value = array('1', '2', '3');
print_r(pc_permute($value));