title: divide samples (numbers) into tests (in the form of intervals)
body: <p>I am trying to divide samples (numbers) into tests (in the form of intervals). But my results are not correct as per the below required result. The code below is working fine till samples of 20 or less than 20. But if more than 20 samples, the results are wired.</p>
  <p><strong>The result should come with this case :</strong></p>
  <p>If 19 samples - 2 tests:  1-10, 11-19</p>
  <p>If 20 samples - 2 tests:  1-10, 11-20</p>
  <p>If 21 samples - 3 tests:  1-10, 11-16, 17-21</p>
  <p>If 23 samples - 3 tests:  1-10, 11-17, 18-23</p>
  <p>If 24 samples - 3 tests:  1-10, 11-17, 18-24</p>
  <p>If 31 samples - 4 tests:  1-10, 11-20, 21–26, 27-31.</p>
  <pre><code>&lt;?php
  $samples = 23;
  $tests = 1;
  
  if($samples &gt; 10) {
      $tests = ceil($samples/10);
  }
  
  echo $tests.&quot; tests\n&quot;;
  
  $s = 1
  for ($x = 0; $x &lt; $tests; $x++) {
  
      if($samples &gt; 20) {
          $c = $s.'-'.ceil($samples/$tests);
      }
      if($x &gt; 0) {
          $c = (ceil($samples/$tests)+1).'-'.$samples;
      }
      echo $c.&quot;\n&quot;;
  }
  ?&gt;
  </code></pre>
  <p><strong>Result coming which is wrong:</strong></p>
  <p>3 tests : 1-8, 9-23, 9-23</p>