我想在這個表和每一列和每一列:如何在桌子上PHP
$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>";
例子:
============= ================================
|令牌/文件| Doc.1 | Doc.2 | Doc.3 | Doc.4 | Doc.5 |
=============================================
|技術........... | .... 5 ..... | .... 7 ..... | .... 4 ..... | .... 2 ..... | .... 1 ..... |
|語言............. | .... 6 ..... | .... 8 ..... | .... 1 ..... | .. ..5 ..... | .... 5 ..... |
|鎮.................... | .... 5 ..... | .... 3 ..... | .... 2。 .... | .... 7 ..... | .... 6 ..... |
|小工具................. | .... 4 ..... | .... 1 ..... | .... 2 .... 。| .... 4 ..... | .... 8 ..... |
|智能手機......... | .... 3 ..... | .... 7 ..... | .... 3 ..... | .... 1。 .... | .... 2 ..... |
=============================================
結果............... | .... 23 .... | .... 26 .... | .... 12 .... | .... 19 .... | 22 .... |
如何求和每列?
ok..thanks對您有所幫助。但是,如果我想使用存儲在數組中的數字,我該怎麼辦?例如:$ random = rand(1,8)改爲$ random = array(1,2,3,...,25)?? – bob 2013-05-07 03:51:32
要直接在數組中選擇一個值,您可以執行'$ random [$ i]',其中'$ i'介於'0'和'count($ random)'之間。如果你想隨機選擇你可以使用['array_rand()'](http://php.net/manual/en/function.array-rand.php) - 'array_rand($ random)'' – Sean 2013-05-07 04:02:16