I have a dynamically created array $array=[2,3,2]
. I want to loop through it and get all the possible permutations.
$array = [2,3,2];
$c = count($array);
for($i=0; $i<$c; $i++) {
for($j=0; $j<$array[$i]; $j++) {
echo ($i+1).'-'.($j+1).'<br>';
}
}
The result should be something like:
1-1-1
1-1-2
1-2-1
1-2-2
1-3-1
1-3-2
2-1-1
2-1-2
2-2-1
2-2-2
2-3-1
2-3-2
but it returns that:
1-1
1-2
2-1
2-2
2-3
3-1
3-2