這裏我有一個循環,其中包含行號爲<table>
的5個名稱。這table
應該是一個排名,其中第一列將顯示一行參與者名稱,其他10列應顯示分數。獲取PHP數組值並將其打印在不同的列上
對於我想添加分數的空列,我想爲每個參與者創建一個array
,並使其通過<td>
循環。進入array
有10個數字,每個數字應顯示在每個空的<td>
左側。
//Names
$names = array("Mike", "Kyle", "Johnny", "Will", "Vasques");
//scores values for each name
$scores = array(
"Mike" => array(04, 03, 00, 07, 04, 07, 00, 01, 00, 07, 04),
"Kyle" => array(07, 01, 00, 03, 04, 01, 00, 07, 03, 04, 04),
"Johnny" => array(07, 07, 00, 03, 00, 04, 00, 01, 01, 04, 03),
"Will" => array(03, 04, 00, 03, 04, 07, 00, 01, 00, 07, 04),
"Vasques" => array(03, 01, 00, 03, 04, 07, 00, 01, 00, 07, 07)
);
//start loop for rows
for($x=0; $x<count($names); $x++) {
echo "<tr>";
//column for the names
echo "<td>$names[$x]</td>";
//loop for columns where the score should be displayed
for($td=2; $td<=10; $td++) {
echo "<td></td>";
}
echo "</tr>";
}
它應該顯示是這樣的:
Mike 04 03 00 07 04 07 00 01 00 07 04
Kyle 07 01 00 03 04 01 00 07 03 04 04
Johnny 03 01 00 03 04 07 00 01 00 07 07
等等...
你會不會只是更換回聲 「?」;與回聲「{$ scores [$ names [$ x]] [$ td - 2]}」 –
您需要交叉驗證'$ names'與'$ scores' ?,或者只是簡單地打印出$在桌上的分數?一個簡單的foreach應該足夠了 – user1978142
請問你爲什麼要發佈這個你以前發佈的這個奇怪的切線版本的問題? http://stackoverflow.com/questions/24236002/get-php-array-values-and-print-in-a-loop – JakeGould