Ungetestet aber etwa so
PHP
- <?php
- $data = [
- [
- 'datum' => '1927.09.23',
- 'hans wurst' => '2-3-4-7',
- 'sepp kase' => '9-4-2-2',
- ],
- [
- 'datum' => '2015.01.01',
- 'hans wurst' => '6-2-0-1',
- 'sepp kase' => '0-2-3-8',
- ],
- ];
- $tmp = [];//ein array erstellen
- $i = 0;
- while (is_array($data[$i])) {//mal deine while-schleife faken
- $row = $data[$i];
- //und los gehts
- $datum = date("d-m-Y", strtotime($row['datum']));
- unset($row['datum']);
- if ($i == 0) {//erster schleifen durchgang
- $output .= '<tr><th>Datum</th>';
- foreach ($row as $name => $trash) {
- $output .= '<th colspan="4">'.$name.'</th>';
- $tmp[$name] = [];//für jeden namen ein array erstellen
- }
- $output .= '</tr><tr><th></th>';
- foreach ($row as $trash) {
- $output .= '<th>H</th><th>N</th><th>K</th><th>F</th>';
- }
- $output .= '</tr>';
- }
- $output .= '<tr><td>'.$datum.'</td>';
- foreach ($row as $name => $points) {
- $points = explode('-', $points);
- $tmp[$name][] = $points;//In das array mit dem namen ein neues array mit den punkten des Datums geben
- $output .= '<td>'.$points[0].'</td><td>'.$points[1].'</td><td>'.$points[2].'</td><td>'.$points[3].'</td>';
- }
- $output .= '</tr>';
- //das hier gehört zum fake
- $i++;
- }
- $output .= '<tr><td>Ø</td>';
- foreach ($tmp as $name => $array) {
- $h = 0;$n = 0;$k = 0;$f = 0;
- foreach ($array as $points) {//punkte aus den daten zusammenzählen
- $h += $points[0];
- $n += $points[1];
- $k += $points[2];
- $f += $points[3];
- }
- $output .= '<td>'.($h / 4).'</td><td>'.($n / 4).'</td><td>'.($k / 4).'</td><td>'.($f / 4).'</td>';
- }
- $output .= '</tr>';
- ?>
- <table border="1" cellpadding="5">
- <?php echo $output; ?>
- </table>