php - How can I convert 1D array from numbers to 2D array? -


i have array numbers :

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

i tried convert 2d using 2 loops failed. better try foreach loop , or can done for-s ?

i wanna make this:

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

the reason i'm posting answer question , availability of array_chunk() may not intuitive:

$array = array_chunk($array, 4); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -