eval.in

Paste #4511

PHP — PHP 5.4.6, pasted 1 year ago

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
<?php

$array = [0, 1 ,2 ,3, 0, 4, 5];
$parts = [];
$index = 0;

foreach ($array as $key => $number)
{
    $number == 0 and $key and $index++;
    $parts[$index][$key] = $number;
}

print_r($parts);

Program Output

Array
(
    [0] => Array
        (
            [0] => 0
            [1] => 1
            [2] => 2
            [3] => 3
        )

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

)

OK (0.008 sec real, 0.011 sec wall, 13 MB, 217 syscalls)

Fork