Transpose an indexed array of indexed arrays

Viewed 275

I have a multidimensional array which looks like below example:

$collection = array(
  0 => array (
      0 => '1002',        //Push to new array1
      1 => '1003'         //Push to new array2
  ),
  1 => array(
      0 => '7',        //Push to new array1
      1 => '7'         //Push to new array2
  ),
  2 => array(
      0 => 'This is my first comment in the box',        //Push to new array1
      1 => '1This is my first comment in the box'        //Push to new array2
  ),
  3 => array(
      0 => '2014-01-01 01:16:05',        //Push to new array1
      1 => '2014-01-01 01:16:05'         //Push to new array2
  )
);

What i want is this:

$collection = array(
    0 => array (               //Pushed array1 result
        0 => '1002',
        1 => '7',
        2 => 'This is my first comment in the box',
        3 => '2014-01-01 01:16:05'
    ),
    1 => array (               //Pushed array2 result
        0 => '1003',
        1 => '7',
        2 => 'This is my second comment in the box',
        3 => '2014-01-01 01:16:05'
    )
);

I don't know how can i say with words, but as you can see i want the result which looks above. I've tried much but i'm lost now.

3 Answers
Related