fork download
  1. <?php
  2. $newArray = array();
  3. $total = 30;
  4. $m = 4;
  5. $skip = 4;
  6. for ($i = 1; $i <= $total; $i++) {
  7. $newArray[$i] = $i;
  8. }
  9. unset($i);
  10. echo "<pre>";
  11. print_r($newArray);
  12. echo "</pre>";
  13. $count = count($newArray);
  14.  
  15.  
  16.  
  17.  
  18. for ($k = 1; $k <= $count - $m; $k++) {
  19.  
  20. for ($i = 1; $i < $skip; $i++) {
  21. next($newArray);
  22. $d = current($newArray);
  23.  
  24. if (!isset($newArray[$d])) {
  25. $z = $skip - $i - 1; //2
  26.  
  27. reset($newArray);
  28.  
  29.  
  30. for ($s = 1; $s < $z; $s++) {
  31. next($newArray);
  32. }
  33. $d = current($newArray);
  34. }
  35. }
  36.  
  37. unset($newArray[$d]);
  38.  
  39.  
  40. }
  41.  
  42.  
  43. echo "<pre>";
  44. print_r($newArray);
  45. echo "</pre>";
  46.  
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [1] => 1
    [2] => 2
    [3] => 3
    [4] => 4
    [5] => 5
    [6] => 6
    [7] => 7
    [8] => 8
    [9] => 9
    [10] => 10
    [11] => 11
    [12] => 12
    [13] => 13
    [14] => 14
    [15] => 15
    [16] => 16
    [17] => 17
    [18] => 18
    [19] => 19
    [20] => 20
    [21] => 21
    [22] => 22
    [23] => 23
    [24] => 24
    [25] => 25
    [26] => 26
    [27] => 27
    [28] => 28
    [29] => 29
    [30] => 30
)
</pre><pre>Array
(
    [1] => 1
    [11] => 11
    [15] => 15
    [25] => 25
)
</pre>