2016-05-04 59 views
-1

我與arrayPHP工作,發現故障的,我已經設置陣列像轉換M * N排列到N * M陣列PHP

$x = array(array("Ram","shyam"),array("Hari","Gopal"),array("Rama","Bidhya")) 

現在我想這個數組轉換爲這樣的事情

array(array("Ram","Hari","Rama"),array("Shyam","Gopal","Bidhya")) 

謝謝

+0

[鏈接](https://eval.in/564907)檢查這個環節,我有代碼你,但不能發表,因爲問題被關閉。訪問鏈接... –

回答

1

試試這個

array_unshift()函數將新元素插入到數組中。新的數組值將被插入到數組的開頭。

$x = array(array("Ram","shyam"),array("Hari","Gopal"),array("Rama","Bidhya")); 

function transpose($array) { 
    array_unshift($array, null); 
    return call_user_func_array('array_map', $array); 
} 

$out = transpose($x); 
echo '<pre>'; 
print_r($out); 

結果

Array 
(
    [0] => Array 
     (
      [0] => Ram 
      [1] => Hari 
      [2] => Rama 
     ) 

    [1] => Array 
     (
      [0] => shyam 
      [1] => Gopal 
      [2] => Bidhya 
     ) 

) 
相關問題