Remove “columns” from the subarrays of a two dimensional array

I have a simple, two dimensional array like this:

Array
    (
        [0] => Array
            (
                [0] => abc
                [1] => 123
                [2] => aaaaa

            )

        [1] => Array
            (
                [0] => def
                [1] => 456
                [2] => ddddd
            )

        [2] => Array
            (
                [0] => ghi
                [1] => 789
                [2] => hhhhhhh
            )
    )

I'm trying to write an efficient function which will return an array with only the first 'n' columns of each subarray. In other words, if n=2, then the returned array would be:

Array
    (
        [0] => Array
            (
                [0] => abc
                [1] => 123


            )

        [1] => Array
            (
                [0] => def
                [1] => 456

            )

        [2] => Array
            (
                [0] => ghi
                [1] => 789

            )
    )
7
задан NikiC 13 September 2010 в 17:00
поделиться