转换我的MultiArray

时间:2010-12-23 16:53:10

标签: php

有阵列

   $A = 
      Array
      (
     [0] => Array ([0] => aaa)

     [1] => Array([0] => bbb)

     [2] => Array([1] => ccc)

     [3] => Array([1] => ddd)
    )




   $B = array();
    chang_arr($A){

    //TODO  


    }

将得到一个像这样的数组$ B

    Array
    (
 [0] => Array ([0] => aaa
        [1] => bbb
      )
 [1] => Array([0] => ccc
      [1] => ddd
      )
    )

1 个答案:

答案 0 :(得分:2)

function chang_arr($A){ 
   $B = array();
   foreach($A as $ar) {
      foreach($ar as $k => $v) {
         $B[$k][] = $v
      }
   }
   return $B;
}

$B = chang_arr($A);