I see it occasionally, so I print it out in PHP.
There are two ways to resolve this issue:
Method One: According to the graph analysis of the graph is a two-dimensional array, two-dimensional array can solve such problems, 6 rows is 6 arrays, each row represents the array of how many elements. If you know the number of elements in each array, do you know which elements are in the array?
function array_chunk_vertical ($arr, $colun) { $arr _length = count ($arr); $parem = Floor ($arr _length/$colun); $pare = $arr _length% $colun; $ar = Array (); for ($i = 0; $i < $colun; $i + +) { $par = $i = = $colun-1? 1:5; $ar [] = $par; } $newarray = Array (); foreach ($ar as $value) {for ($i = 0; $i < $value; $i + +) { $newarray [$i] = Array_shift ($arr); } } return $newarray;} $arr = Range (1, +), $data = Array_chunk_vertical ($arr, 7), foreach ($data as $value) { foreach ($value as $va) { printf (' [%2s] ', $va); } echo "<br/>";}
Method Two: such as code, first give a size empty array, the empty array to fill the element. Here's how:
<?php function array_chunk_vertical ($input, $size, $preserve _keys = False, $size _is_horizontal = False) { $chunks = Array (); if ($size _is_horizontal) { $chunk _count = ceil (count ($input)/$size); } else { $chunk _count = $size; } For ($chunk _index = 0; $chunk _index < $chunk _count; $chunk _index++) { $chunks [] = Array (); } $chunk _index = 0; foreach ($input as $key = + $value) { if ($preserve _keys) { $chunks [$chunk _index][$key] = $value; } else { $chunks [$chunk _index][] = $value; } if (+ + $chunk _index = = $chunk _count) { $chunk _index = 0; } } return $chunks;} $data =range (1,31), $newdata =array_chunk_vertical ($data, 6), foreach ($newdata as $root) { foreach ($root as $val) { printf (' [%2s] ', $val); } echo "<br/>";}
How does the PHP algorithm------------print out