[ create a new paste ] login | about

Link: http://codepad.org/gQW9n9ty    [ raw code | output | fork ]

PHP, pasted on Oct 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php

    $rows = array(
        'a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5,
        'f' => 6, 'g' => 7, 'h' => 8, 'i' => 9, 'j' => 10
    );

    $result = array();
    
    $i = 0;
    foreach($rows as $key => $value) {
        $result[$i++ % 2][$key] = $value;
    }

    print_r($result);


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Array
(
    [0] => Array
        (
            [a] => 1
            [c] => 3
            [e] => 5
            [g] => 7
            [i] => 9
        )

    [1] => Array
        (
            [b] => 2
            [d] => 4
            [f] => 6
            [h] => 8
            [j] => 10
        )

)


Create a new paste based on this one


Comments: