I have this array :
$products = array('0', '1', '2', '3');
and I want to have this combination :
0
0,1
0,1,2
0,1,2,3 // my code can't show this result
0,1,3 // my code can't show this result
0,2
0,2,3
0,3
1
1,2
1,2,3
1,3
2
2,3
3
and here's my code :
$rows = count($products);
for ($i = 0; $i < $rows; $i++) {
echo $i . '<br>';
for ($j = $i + 1; $j < $rows; $j++){
echo $i . $j . '<br>';
if (!empty($products[$j+1])) {
echo $i . $j . $products[$j+1] . '<br>';
}
}
}
but, unfortunately I missed 2 results :
0,1,2,3
0,1,3
and I still have doubt about this for
loop inside loop, while the number of combination is determined by array length.
how to get that missed combination and perfectly works for different array length?