$arr = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
$max_num_cols = 4; //the maximum amount of columns that can be output
$min_items_per_col = 5; //The minimum amount of items per column
$col_limit_calculation = $max_num_cols * $min_items_per_col; //used to determine which value to chunk by
$num_rows = count($arr); //total number of items in the array
//determins how many values to chunk our array by while still keeping with our $max_num_cols
$chunk_count = ($num_rows >= $col_limit_calculation) ? ceil(($num_rows / $max_num_cols)) : $min_items_per_col;
//The chunked array that we get to loop through now
$alphabet_chunk_array = array_chunk($arr, $chunk_count);
echo "<table border="1"><tr>";
foreach ($alphabet_chunk_array as $alphabet_array) {
echo "<td valign="top">";
foreach ($alphabet_array as $alphabet) {
echo $alphabet . "<br />";
}
echo "</td>";
}
echo "</tr></table>";
|
{html_table loop=$arr cols=4}Resource
Smarty html_table documentation
Cheers