0
Pls Clarify the issue


My Function :


function makeCombination ($my_arr, $k){
reset($my_arr);
$enne=count($my_arr);
//echo "$enne";

$num_comb=$this->numComb($enne,$k);

//echo "$num_comb";
$combinations=array();
$pos=array();

for( $i = $k; $i > 0; $i--) { 
$pos[$i] = $i;   

}

$counter=0;

while(true) {  


$temp=array();
$i=$k;

$counter +=1;


if ($counter>1){
while($i-- > 0) {

$temp[$i] = $my_arr[$pos[$i]]; 

}
}
else{

for ($i=$k;$i>0;$i--){
    //$i1=$i-1;
$temp[$i-1] = $my_arr[$pos[$i]-1]; 
}
print_r($temp);
}


$combinations[]=$temp;
reset($combinations);

$i=1;


 while(($i < $k) && (($pos[$i-1] + 1) == $pos[$i])) ++$i;  

   if(++$pos[--$i] >= $enne)  
   break;  
    while(--$i >= 0){
  $pos[$i] = $i;    

}



}

reset($combinations);
return $combinations;


}



my php :

  include "Combinatorics.php";
                        $mycalc=new Combinatorics;
                       for($j=0; $j<sizeof($productdetails); $j++)
                        {
                        $combwr=$mycalc->makeCombination(array($productdetails[$j]['nam']),$notitle);
                        echo"and they are the followings:</BR>";
                        foreach($combwr as $key=>$value){
                        echo $key .": ";
                        foreach ($value as $key2=>$value2){
                        echo $value2;
                        }
                        echo "</BR>";
                        }
                        }
2
Contributors
1
Reply
8
Views
3 Years
Discussion Span
Last Post by phorce
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.