title: Transposing multidimensional arrays in PHP
body: <p>How would you flip 90 degrees (transpose) a multidimensional array in PHP? For example:</p>
  
  <pre><code>// Start with this array
  $foo = array(
      'a' =&gt; array(
         1 =&gt; 'a1',
         2 =&gt; 'a2',
         3 =&gt; 'a3' 
      ),
      'b' =&gt; array(
         1 =&gt; 'b1',
         2 =&gt; 'b2',
         3 =&gt; 'b3' 
      ),
      'c' =&gt; array(
         1 =&gt; 'c1',
         2 =&gt; 'c2',
         3 =&gt; 'c3' 
      )
  );
  
  $bar = flipDiagonally($foo); // Mystery function
  var_dump($bar[2]);
  
  // Desired output:
  array(3) {
    ["a"]=&gt;
    string(2) "a2"
    ["b"]=&gt;
    string(2) "b2"
    ["c"]=&gt;
    string(2) "c2"
  }
  </code></pre>
  
  <p>How would you implement <code>flipDiagonally()</code>?</p>
  
  <p>Edit: this is not homework. I just want to see if any SOers have a more creative solution than the most obvious route. But since a few people have complained about this problem being too easy, what about a more general solution that works with an n<sup>th</sup> dimension array?</p>
  
  <p>i.e. How would you write a function so that:</p>
  
  <pre><code>$foo[j][k][...][x][y][z] = $bar[z][k][...][x][y][j]
  </code></pre>
  
  <p>?(ps. I don't think 12 nested <code>for loops</code> is the best solution in this case.)</p>