I'm trying to display a list of models in four columns, I'm doing this using codeigniters table library. Currently I'm passing an alphabetised list of models to a view and then using array_chunk to split the array into groups of four and then passing that to the CI table generator. This creates 4 columns which are alphabetical left to right.
<?php
// Build an array of models
$models_array = array();
foreach($product->compatible_models as $model)
{
$models_array[] = $model['brand'] . ' ' . $model['model'];
}
// Split the array into chunks of 4
$data = array_chunk($models_array, 4);
// Display the data using codeigniters table library
$tmpl = array ( 'table_open' => '<table border="0" cellpadding="2" cellspacing="1" width ="100%" class="mytable">' );
$this->table->set_template($tmpl);
$this->table->set_heading(NULL);
echo $this->table->generate($data);
?>
Is there a way I can modify the $models_array so that the elements are sorted in such a way as to be output reading alphabetically top to bottom down each column rather than across? So that:
a,b,c,d,e,f,g,h,i,j,k
=
a | b | c | d
e | f | g | h
i | j | k
Becomes:
a,d,g,j,b,e,h,k,c,f,i
=
a | d | g | j
b | e | h | k
c | f | i