fork(2) download
  1. <?php
  2. $start = range(0,30);
  3. $length = array(3,7,2,12,6);
  4.  
  5. $target_array = array();
  6. foreach($length as $i) {
  7. $target_array[] = array_splice($start, 0, $i);
  8. }
  9.  
  10. var_dump($target_array);
Success #stdin #stdout 0.02s 13064KB
stdin
Standard input is empty
stdout
array(5) {
  [0]=>
  array(3) {
    [0]=>
    int(0)
    [1]=>
    int(1)
    [2]=>
    int(2)
  }
  [1]=>
  array(7) {
    [0]=>
    int(3)
    [1]=>
    int(4)
    [2]=>
    int(5)
    [3]=>
    int(6)
    [4]=>
    int(7)
    [5]=>
    int(8)
    [6]=>
    int(9)
  }
  [2]=>
  array(2) {
    [0]=>
    int(10)
    [1]=>
    int(11)
  }
  [3]=>
  array(12) {
    [0]=>
    int(12)
    [1]=>
    int(13)
    [2]=>
    int(14)
    [3]=>
    int(15)
    [4]=>
    int(16)
    [5]=>
    int(17)
    [6]=>
    int(18)
    [7]=>
    int(19)
    [8]=>
    int(20)
    [9]=>
    int(21)
    [10]=>
    int(22)
    [11]=>
    int(23)
  }
  [4]=>
  array(6) {
    [0]=>
    int(24)
    [1]=>
    int(25)
    [2]=>
    int(26)
    [3]=>
    int(27)
    [4]=>
    int(28)
    [5]=>
    int(29)
  }
}