Transposing multidimensional arrays in PHP -


How do you move a multi-dimensional array in PHP (90 degrees)? For example: $ foo = array ('a' = & gt; array (1 = & gt; 'a1', 2 = & gt; 'a2', 3 = array (1 = & gt; 'B' from this array 1 ', 2 = & gt;' B2 ', 3 = & gt;' B3 '),' C '= & gt; array (1 = & gt; C1', 2 = & gt; C 2 ', 3 = & gt;' C3 '); $ Bar = flipDiagonally ($ foo); // Mystery Function var_dump ($ bar [2]); // desired output: array (3) {["a String (2) "B2" ["c"] = & gt; String (2) "C2"} / Code>

How do you edit: flipDiagonally () ?

This is not a homework. I just want to see if any of the most Clear mother There is a more constructive solution than GG. But when some people have complained about this problem, then it is not easy, about a more general solution that is with the value of n th How do you write a function so that:

  $ foo [j] [k] [...] [x] [y] [?] Z] = $ bar [z] [k] [...] [x] [y] [j]  

? (Ps. I do not think 12 nested loops is the best solution for this case.)

  function transfer ($ Array) {array_unshift ($ array, null); Return call_user_func_array ('array_map', $ array); }  

or if you are using PHP 5.6 or later:

  function transfer ($ array) {return array_map (empty, ... $ Array); }  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -