[ create a new paste ] login | about

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

PHP, pasted on Dec 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

$rows = array(
    array( 'Name', 'Email', 'Address' ),
    array( 'vanson', 'dhmax@pan.com', 'gurgaon' ),
    array( 'john' ),
    array( 'sdf', 'sdfsdf', 'sdfsd' ),
);

function array_transpose( $array ) {
    $array = array_merge( array( null ), array_values( $array ) );
    return call_user_func_array( 'array_map', $array );
}

$columns = array_transpose( $rows );

print_r( $columns );


Output:
Array
(
    [0] => Array
        (
            [0] => Name
            [1] => vanson
            [2] => john
            [3] => sdf
        )

    [1] => Array
        (
            [0] => Email
            [1] => dhmax@pan.com
            [2] => 
            [3] => sdfsdf
        )

    [2] => Array
        (
            [0] => Address
            [1] => gurgaon
            [2] => 
            [3] => sdfsd
        )

)


Create a new paste based on this one


Comments: