title: How to reduce for loop speed
body: <p>i'm facing a big issue.  i need to generate exact 7 number combinations and i written a code for that by using 7 forloops and also it is working fine with very less numbers.Please check the attachment so you will be very clear what i need actually. 
  Please provide PHP result.</p>
  
  <pre><code>&lt;?php
  // I need the combinations for this commented numbers   
  // 1, 7, 13, 19, 25, 31, 2, 8, 14, 20, 26, 32, 3, 9, 15, 
  // 21, 27, 33, 4, 10, 16, 22, 28, 34, 5, 11, 17, 23, 29,
  // 35, 6, 12, 18, 24, 30, 36
  $string=array(1,7,13,19,25,31,2,8,14,20,26,32,3,9,15,21,27,33,4,10,16,22,28,34);
  $len=count($string);
  $c=0;
  ob_start();
  for ($e = 0; $e &lt; $len - 6; $e++)
  {
     for ($f = $e+1; $f &lt; $len - 5; $f++)
     {
         for ($g = $f+1; $g &lt; $len - 4; $g++)
         {
             for ($h = $g+1; $h &lt; $len - 3; $h++)
             { 
                 for ($i = $h+1; $i &lt; $len - 2; $i++)
                 {
                     for ($j = $i + 1; $j &lt; $len - 1; $j++)
                     {
                          for ($k = $j + 1; $k &lt; $len; $k++)
                          {
                               $c++;
                               $output[] = $string[$e] . "," . 
                                           $string[$f] . "," . 
                                           $string[$g] . "," .  
                                           $string[$h] . "," . 
                                           $string[$i] . "," . 
                                           $string[$j] . "," . 
                                           $string[$k];
                               ob_flush();
                          }
                          ob_flush();
                     }
                     ob_flush();
                 }
                 ob_flush();
             }
             ob_flush();
     }
     ob_flush();
  }
  ob_flush();
  }
  echo count($output);
  ?&gt;
  </code></pre>
  
  <p>And I need the output same like i mentioned below. 
  Output: </p>
  
  <pre><code>passed numbers $string=array(1, 7, 13, 19, 25, 31, 2, 8, 14) and the out put is below
  count of combinations = 36
  Array
  (
      [0] =&gt; 1,7,13,19,25,31,2
      [1] =&gt; 1,7,13,19,25,31,8
      [2] =&gt; 1,7,13,19,25,31,14
      [3] =&gt; 1,7,13,19,25,2,8
      [4] =&gt; 1,7,13,19,25,2,14
      [5] =&gt; 1,7,13,19,25,8,14
      [6] =&gt; 1,7,13,19,31,2,8
      [7] =&gt; 1,7,13,19,31,2,14
      [8] =&gt; 1,7,13,19,31,8,14
      [9] =&gt; 1,7,13,19,2,8,14
      [10] =&gt; 1,7,13,25,31,2,8
      [11] =&gt; 1,7,13,25,31,2,14
      [12] =&gt; 1,7,13,25,31,8,14
      [13] =&gt; 1,7,13,25,2,8,14
      [14] =&gt; 1,7,13,31,2,8,14
      [15] =&gt; 1,7,19,25,31,2,8
      [16] =&gt; 1,7,19,25,31,2,14
      [17] =&gt; 1,7,19,25,31,8,14
      [18] =&gt; 1,7,19,25,2,8,14
      [19] =&gt; 1,7,19,31,2,8,14
      [20] =&gt; 1,7,25,31,2,8,14
      [21] =&gt; 1,13,19,25,31,2,8
      [22] =&gt; 1,13,19,25,31,2,14
      [23] =&gt; 1,13,19,25,31,8,14
      [24] =&gt; 1,13,19,25,2,8,14
      [25] =&gt; 1,13,19,31,2,8,14
      [26] =&gt; 1,13,25,31,2,8,14
      [27] =&gt; 1,19,25,31,2,8,14
      [28] =&gt; 7,13,19,25,31,2,8
      [29] =&gt; 7,13,19,25,31,2,14
      [30] =&gt; 7,13,19,25,31,8,14
      [31] =&gt; 7,13,19,25,2,8,14
      [32] =&gt; 7,13,19,31,2,8,14
      [33] =&gt; 7,13,25,31,2,8,14
      [34] =&gt; 7,19,25,31,2,8,14
      [35] =&gt; 13,19,25,31,2,8,14
  )
  </code></pre>