bledileka
Programmer
- Nov 15, 2006
- 16
Hello !
Im got this array :
$numra=array(1,2,3,4,5,6....); //x numbers, max 90
Well, now i want to find all the possible unique combinations of this keys, i came up with something but i got problems on distinguing combinations.
Example : 1 - 4 - 3 - 5 - 6 is equal to 1 - 4 - 3 - 6 - 5. I need to show only one of this two.
This is the code (a real mess ) :
Can anyone help me on this ???
Im got this array :
$numra=array(1,2,3,4,5,6....); //x numbers, max 90
Well, now i want to find all the possible unique combinations of this keys, i came up with something but i got problems on distinguing combinations.
Example : 1 - 4 - 3 - 5 - 6 is equal to 1 - 4 - 3 - 6 - 5. I need to show only one of this two.
This is the code (a real mess ) :
Code:
$numra=array(1,2,3,4,5,6); //x numra mund te vendosen
$sas=count($numra);
for ($i=0;$i<=$sas;$i++) {
$n2=$numra;
$s2=count($n2);
for ($j=$i+1;$j<=$s2;$j++) {
if ($n2[$j]<>$numra[$i]) {
$n3=$n2;
$s3=count($n3);
for ($k=$i+2;$k<=$s3;$k++) {
if (($n3[$k]<>$n2[$j]) & ($n3[$k]<>$numra[$i])) {
$n4=$n3;
$s4=count($n4);
for ($l=$i+3;$l<=$s4;$l++) {
if (($n4[$l]<>$n3[$k])&($n4[$l]<>$n2[$j])&($n4[$l]<>$numra[$i])) {
$n5=$n4;
$s5=count($n5);
for ($m=$i+4;$m<=$s5;$m++) {
if (($n5[$m]<>$n4[$l])&($n5[$m]<>$n3[$k])&($n5[$m]<>$n2[$j])&($n5[$m]<>$numra[$i])) {
if ((isset($n2[$j]))&(isset($n3[$k]))&(isset($n4[$l]))&(isset($n5[$m]))) {
$xx=$numra[$i]+$n2[$j]+$n3[$k]+$n4[$l]+$n5[$m];
$v[]=$xx;
if (in_array($xx,$v)) {
$tot++;
echo $numra[$i]; echo " - ";echo $n2[$j];echo " - ";echo $n3[$k];echo " - ";echo $n4[$l];echo " - ";echo $n5[$m];echo "<br>";
}
}}}}}}}}
}}echo $tot." Kombinacione !";