I have table that is dynamically created from an array. Using PHP, how can I dynamically add rowspan when the data is repeated? I would like 'Youth Classes' to be displayed only once and have a rowspan=2.
Array
(
[0] => Array
(
[Type] => Youth Classes
[Class] => Preschool Class
[Day] => Saturday
)
[1] => Array
(
[Type] => Youth Classes
[Class] => Grade School
[Day] => Friday
)
)
<?php
/*Load csv file into array*/
$file = 'list.csv';
$rows = array_map('str_getcsv', file($file));
$headers = array_shift($rows);
$csv = array();
foreach($rows as $row) {
$csv[] = array_combine($headers, $row);
}
/*Build Table*/
echo "\t\t<table class='table'>\n";
echo "\t\t\t<tr>\n";
foreach ($headers as $header) {
echo "\t\t\t\t<th>";
echo $header;
echo "</th>\n";
}
echo "\t\t\t</tr>\n";
foreach ($csv as $row) {
echo "\t\t\t<tr>\n";
foreach ($row as $cell) {
echo "\t\t\t\t<td>";
echo $cell;
echo "</td>\n";
}
echo "\t\t\t</tr>\n";
}
echo "\t\t</table>\n";
?>
