Wie die Summe in jeder Spalte der Tabelle PHP

Ich möchte die Summe in jeder Spalte dieser Tabelle:

$docid = array(1, 2, 3, 4, 5);
        $table = array('technology' => 1 , 'languange' => 2, 'town' => 3, 'gadget' => 4, 'smartphone' => 5);
        echo "<table><tr><th>Token/Document</th>";
        $count = count($table);
        $doc_count = count($docid);
        for($i=1; $i<=$count; $i++)
        {
            echo "<th>Doc.$i</th>";
        }
        foreach($table as $key=>$value)
        {
            echo "<tr><td>$key</td>";
            for($i=0; $i<$doc_count;$i++)
            {
                $random = rand(1, 8);
                echo "<td>$random</td>";
            }
        }
        echo "</tr><td>RESULT</td>";
        for($i=0; $i<$doc_count;$i++)
        {
            echo "<td>...(what should i use?)...</td>";
        }
        echo "</tr></table>";

Beispiel:

=============================================

| Token/Dokument | Doc.1 | Doc.2 | Dok.3 | Dok.4 | Dok.5 |

=============================================

| Technologie...........|....5.....|....7.....|....4.....|....2.....|....1.....|

| Sprache.............|....6.....|....8.....|....1.....|....5.....|....5.....|

| Stadt....................|....5.....|....3.....|....2.....|....7.....|....6.....|

| gadget.................|....4.....|....1.....|....2.....|....4.....|....8.....|

| smartphone.........|....3.....|....7.....|....3.....|....1.....|....2.....|

=============================================

ERGEBNIS...............|....23....|....26....|....12....|....19....| 22....|

Wie die Summe jeder Spalte?

InformationsquelleAutor bob | 2013-05-07
Schreibe einen Kommentar