/ Published in: PHP
Function to convert a one dimensional array to two dimensional with option to specify how many columns. Returns two dimensional array on success or false on fail.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function array_2d($array, $col_count=2){ $result = false; $pointer = 0; for($row=0; $row < $row_count; $row++) { for($col=0; $col < $col_count; ++$col){ $result[$row][$col] = $array[$pointer]; $pointer++; } } } } return $result; } $result = array_2d($test, 3); ?>