dongzongxun8491 2015-03-31 18:41
浏览 195
已采纳

如何将1D数组从数字转换为2D数组?

I have an array from numbers like this :

$array = array (1,2,3,4,5,6,7,8,9,10,11,12);

I tried to convert it to 2D using two for loops but i failed. Is it better to try with foreach loop , or it can be done with for-s ?

I wanna make something like this:

$array = array (array (1,2,3,4), array(5,6,7,8), array(9,10,11,12));
  • 写回答

1条回答 默认 最新

  • doutinghou6980 2015-03-31 18:42
    关注

    The reason I'm posting an answer is that a question like this and the availability of array_chunk() may not be very intuitive:

    $array = array_chunk($array, 4);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?