Okay, so array_map(null, $array1, $array2, $array, ...)
can be used to zip several arrays together. array_map(null, [1,2,3], [4,5,6]) == [[1,4], [2,5], [3,6]]
. And then you've got the destructuring operator "...
" and now you can have a general array-transpose operation:
$array = [[1,2,3], [4,5,6], [7,8,9]];
array_map(null, ...$array) == [[1,4,7], [2,5,8], [3,6,9]];
Which is all well, and good. But TIL:
array_map(null, ...[[a,b,c], [d,e,f], [g,h,i], [j,k,l]]) == [[a,d,g,j], [b,e,h,k], [c,f,i,l]]
array_map(null, ...[[a,b,c], [d,e,f], [g,h,i]]) == [[a,d,g], [b,e,h], [c,f,i]]
array_map(null, ...[[a,b,c], [d,e,f]]) == [[a,d], [b,e], [c,f]]
array_map(null, ...[[a,b,c]]) == [a, b, c]
4 arrays of 3 elements each becomes 3 arrays of 4 elements each
3 arrays of 3 elements each becomes 3 arrays of 3 elements each
2 arrays of 3 elements each becomes 3 arrays of 2 elements each
1 array of 3 elements each becomes 1 array of 3 elements each
One of these things is not like the others. And apparently it's not a bug. array_map(null, ...[[a,b,c]])
is equivalent to array_map(null, [a,b,c])
as it should be, but it was decided that the latter should be a no-op and just return its second argument unchanged.