Reputation: 11
Hi I have a 1D array (1 by 20) that I would like to transform to a 2D Array (4 by 5)
$winning_number = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
to
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
right now I am using this code:
foreach ($wining_no as $boulex)
{
for($i=0;$i<$5;$i++)
{
if($i==0)
{
for($j=0;$j<$4;$j++)
{
$boule_array[$j][$i] = $boulex;
}
}
}
}
For some reason this does not work
Upvotes: 1
Views: 287
Reputation: 2597
You could use the array_chunk($array, $size)
function
For you it would be like this
array_chunk($winning_number, 5);
Upvotes: 2