php二维数组组合算法

1,671次阅读
没有评论

<pre lang='php'>

function combin($CombinList){
 $CombineCount = 1;
 foreach($CombinList as $Key => $Value){
  $CombineCount *= count($Value);
 }
 $RepeatTime = $CombineCount;
 foreach($CombinList as $ClassNo => $StudentList){
  $RepeatTime = $RepeatTime/count($StudentList);
  $StartPosition = 1;
  foreach($StudentList as $Student){
   $TempStartPosition = $StartPosition;
   $SpaceCount = $CombineCount/count($StudentList)/$RepeatTime;
   echo $SpaceCount.'<br/>';
   for($J = 1; $J <= $SpaceCount; $J ++){
    for($I = 0; $I < $RepeatTime; $I ++){
     $Result[$TempStartPosition + $I][$ClassNo] = $Student;
    }
    $TempStartPosition += $RepeatTime * count($StudentList);
   }
   $StartPosition += $RepeatTime;
  }
 }
 return $Result;
}

</pre>

正文完
 

公众号