fork(1) download
  1. <?php
  2.  
  3. $data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, 16];
  4. $chunkLength = 3;
  5. $result = [];
  6.  
  7. while(count($data)) {
  8. $result[] = array_splice($data, 0, $chunkLength);
  9. $chunkLength = $chunkLength === 3 ? 2 : 3;
  10. }
  11.  
  12. print_r($result);
Success #stdin #stdout 0s 82560KB
stdin
Standard input is empty
stdout
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [1] => Array
        (
            [0] => 4
            [1] => 5
        )

    [2] => Array
        (
            [0] => 6
            [1] => 7
            [2] => 8
        )

    [3] => Array
        (
            [0] => 9
            [1] => 10
        )

    [4] => Array
        (
            [0] => 11
            [1] => 12
            [2] => 13
        )

    [5] => Array
        (
            [0] => 14
            [1] => 15
        )

    [6] => Array
        (
            [0] => 16
        )

)