tags:

views:

362

answers:

1
$a=array(array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0),  array(1,0,0),array(1,0,0),array(1,0,0),array(1,0,0));
$rest=array(array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0),  array(0,0,0),array(0,0,0),array(0,0,0),array(0,0,0));

$det = explode(",",'20,20,20,20,20,20,20,20,20,20,20,20,20,20,20');
$cur = explode(",",'0,0,0,0,0,0,0,0,0,0,0,0,0,0,0');
$curval = explode(",",'0,0,0,0,0,0,0,0,0,0,0,0,0,0,0');
$singles = explode(",",'0,0,0,0,0,0,0,0,0,0,0,0,0,0,0');
$noc=1;

$temp=0;
$m=0;
$n=0;
$omit=0;
for($i=0;$i<15;$i++)
{
  ob_start(); 
  for($j=0;$j<3;$j++)
  {
    if($a[$i][$j]!=0)
    { 
      $omit=$a[$i][$j];
      if($rest[$m][$temp]==0)
      {
        $rest[$m][$temp]=$a[$i][$j];
      }
      $temp++;
    }

  }
  if($temp!=0)
  {    
   if($temp>1)
   {
   $det[$m]=$i;
   $cur[$m]=$temp;
   $m++;
   }
   else
     $singles[$i]=$omit;
   $noc=$noc*$temp;
   $temp=0;
   }
   ob_flush();
}

$m1=$m;
$vb=$m;
$p=0;
$resultindex=0;

$p=$noc;
$m=0;
for($nn=0;$nn<count($singles);$nn++)
{ 
  $sing .=$singles[$nn];
  if($nn != (count($singles)-1))
   $sing .=",";
}

for($n=0;$n<$noc;$n++)
{ 

   $result[$n]=explode(",", $sing);
   for($o=0;$o<$vb;$o++)
   { 

     $result[$n][$det[$m]]=$rest[$m][$curval[$m]];


     if((($n+1)%($p/($cur[$m])))==0)
     {
       $curval[$m]++;
       if($curval[$m]>=$cur[$m])
         $curval[$m]=0;
     }
     $p=$p/$cur[$m];
     $m++;
   }
   $p=$noc;
   $m=0;

} 

We are using above code to find the combinations. Is there any possibility to reduce the loops for the above PHP code?

+3  A: 

You cannot reduce this with ease. It will take some work.