fork download
  1. <?php
  2.  
  3. $data = [
  4. 1, 2, 3,
  5. '',
  6. 4, 5, 6, 7,
  7. '',
  8. 8, 9, 10, 11, 12, 13,
  9. ''
  10. ];
  11. print_r($data);
  12.  
  13. $newArray = [];
  14. $i = 0;
  15. foreach($data as $item) {
  16. if(empty($item)) {
  17. ++$i;
  18. continue;
  19. }
  20. else {
  21. $newArray[$i][] = $item;
  22. }
  23. }
  24. print_r($newArray);
Success #stdin #stdout 0s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 
    [4] => 4
    [5] => 5
    [6] => 6
    [7] => 7
    [8] => 
    [9] => 8
    [10] => 9
    [11] => 10
    [12] => 11
    [13] => 12
    [14] => 13
    [15] => 
)
Array
(
    [0] => Array
        (
            [0] => 1
            [1] => 2
            [2] => 3
        )

    [1] => Array
        (
            [0] => 4
            [1] => 5
            [2] => 6
            [3] => 7
        )

    [2] => Array
        (
            [0] => 8
            [1] => 9
            [2] => 10
            [3] => 11
            [4] => 12
            [5] => 13
        )

)