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:
1 4 7 10
2 5 8 11
3 6 9 12
But actually I want to turn it into this:
1 5 9
2 6 10
3 7 11
4 8 12
In other words, I want to flip the rows and columns, but keep the same "width" and "height" of the new array. I've been stuck on this for over an hour.
This is the function I'm using to do a normal "flip" (the first example):
function flip($arr)
{
$out = array();
foreach ($arr as $key => $subarr)
{
foreach ($subarr as $subkey => $subvalue)
{
$out[$subkey][$key] = $subvalue;
}
}
return $out;
}