It may be a lot neat, but I tried to separate things as much as possible and comment on them so that you can understand how it works. Looks like he should do the trick:
$details = array(
1 => array(
1 => 1000,
2 => 'Company A',
3 => '2014-05-10',
4 => '10:00:00',
5 => '15:00:00',
),
2 => array(
1 => 1000,
2 => 'Company A',
3 => '2014-05-11',
4 => '10:00:00',
5 => '15:00:00',
),
3 => array(
1 => 1000,
2 => 'Company B',
3 => '2014-05-10',
4 => '10:00:00',
5 => '15:00:00',
),
4 => array(
1 => 1000,
2 => 'Company B',
3 => '2014-05-11',
4 => '16:00:00',
5 => '19:00:00',
)
);
$flight_dates = array();
$times = array();
$dates = array();
foreach ($details as $flight_details) {
$company_name = $flight_details[2];
$date = $flight_details[3];
$time = $flight_details[4] . ' - ' . $flight_details[5];
$dates[$date] = 1;
$times[$time] = 1;
$flight_dates[$date][$time][] = $company_name;
}
$html = '<table border="1">';
$html .= '<thead>';
$html .= '<tr>';
$html .= '<th> </th>';
foreach ($dates as $date => $value1) {
$html .= '<th>' . $date . '</th>';
}
$html .= '</tr>';
foreach ($times as $time => $value1) {
$html .= '<tr>';
$html .= '<td>' . $time . '</td>';
foreach ($dates as $date => $value2) {
if (!empty($flight_dates[$date][$time])) {
$html .= '<td>' . implode(', ', $flight_dates[$date][$time]) . '</td>';
} else {
$html .= '<td> </td>';
}
}
$html .= '</tr>';
}
$html .= '</table>';
echo $html;
Did the codepad with it, does not appear as a table, which is annoying, but you can copy the html output that it gives you and see how it looks.
source
share