<?php $input = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], ]; $output = array(); $intern = array(); for($row=0; $row < 4; $row++) for($col=0;$col < 3;$col++) $intern[] = $input[$row][$col]; // nesting the array $count = 0; $subcount = 0; foreach($intern as $value) { $output[$count][$subcount] = $value; $count++; if($subcount == 3) { break; } if($count == 4) { $count = 0; $subcount++; } } var_export($output);
You have javascript disabled. You will not be able to edit any code.