PHP - how to flip the rows and columns of a 2D array

后端 未结 10 1385
猫巷女王i
猫巷女王i 2020-12-06 02:24

Normally I\'d be asking how to turn something like this:

1      2        3
4      5        6
7      8        9
10    11       12

Into this:

10条回答
  •  再見小時候
    2020-12-06 03:08

    function flip_row_col_array($array) {
        $out = array();
        foreach ($array as  $rowkey => $row) {
            foreach($row as $colkey => $col){
                $out[$colkey][$rowkey]=$col;
            }
        }
        return $out;
    }
    

提交回复
热议问题