Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

16
  • 20
    NULL is given as the parameter to array_unshift, which adds a value to the start of the array. So, the first line inserts NULL as the first value of the array. The next line calls array_map with all the entries of $array as the parameters. So it's the same as calling array_map(NULL, $array[0], $array[1], $array[2], etc etc). In the array_map documentation there's a detail: "An interesting use of this function is to construct an array of arrays, which can be easily performed by using NULL as the name of the callback function" Commented Apr 26, 2012 at 23:56
  • 15
    This function doesn't keep the indexes if they are of type String. It returns the transposed matrix with numeric index. The flipDiagonally function works fine in this case. Upvote anyways for simplicity Commented Aug 24, 2012 at 14:45
  • 8
    This breaks down when there is only one row e.g. transpose( [[1,2]] ) Expected: [[1],[2]] Actual: [1,2] Commented Mar 16, 2015 at 21:13
  • 5
    should be some description in the answer. Commented Oct 14, 2015 at 11:24
  • 5
    but why does this work? this answer is totally opaque to me Commented Nov 26, 2015 at 12:21