3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], ]; function flip_row_col_array($array) { $out = array(); foreach ($array as $rowkey => $row) { foreach($row as $colkey => $col){ $out[$colkey][$rowkey]=$col; } } return $out; } var_export(flip_row_col_array($array));
Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.30, 8.4.1 - 8.4.18, 8.5.0 - 8.5.3
array ( 0 => array ( 0 => 1, 1 => 4, 2 => 7, 3 => 10, ), 1 => array ( 0 => 2, 1 => 5, 2 => 8, 3 => 11, ), 2 => array ( 0 => 3, 1 => 6, 2 => 9, 3 => 12, ), )

preferences:
110.59 ms | 1399 KiB | 4 Q