Is there better way to transpose a PHP 2D array?

后端 未结 3 1697
[愿得一人]
[愿得一人] 2020-12-11 02:22

According to the PHP Manual, calling array_map with a NULL callback causes it to perform a \"zip\" function, creating an array of arrays of paralle

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 02:55

    If you really want to avoid the array_merge, use array_unshift to prepend the NULL to the $array_of_arrays instead:

    array_unshift($array_of_arrays, NULL);
    call_user_func_array('array_map', $array_of_arrays);
    

    Of course it is not a one-liner anymore :P

提交回复
热议问题