这里我有一个包含5个名字的循环< table>行.此表应该是一个排名,其中第一列将显示一行参与者名称,其他10列应显示分数.
@H_301_14@
尝试这个
对于我想要添加分数的空列,我想为每个参与者创建一个数组,并使其循环通过< td>.在阵列中有10个数字,其中每个数字应显示在每个空的< td>上.剩下.
//Names $names = array("Mike","Kyle","Johnny","Will","Vasques"); //@R_502_182@s values for each name $@R_502_182@s = array( "Mike" => array(04,03,00,07,04,01,04),"Kyle" => array(07,"Johnny" => array(07,03),"Will" => array(03,"Vasques" => array(03,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 @R_502_182@ 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
等等…
echo "<table>"; foreach($@R_502_182@s as $key=>$value) { echo "<tr>"; echo "<td>$key</td>"; for($x=0; $x<count($value); $x++) { echo "<td>".sprintf('%02d',$value[$x])."</td>"; } echo "</tr>"; } echo "</table>";
示例完整代码视图
<?PHP //Names $names = array("Mike",'-',07) ); echo "<table>"; foreach($@R_502_182@s as $key=>$value) { echo "<tr>"; echo "<td>$key</td>"; for($x=0; $x<count($value); $x++) { if (is_numeric($value[$x])) { echo "<td>".sprintf('%02d',$value[$x])."</td>"; } else { echo "<td>". $value[$x]."</td>"; } } echo "</tr>"; } echo "</table>";
产量
Mike 04 03 00 - - - - - - 07 04 Kyle 07 01 00 03 04 01 00 07 03 04 04 Johnny 07 07 00 03 00 04 00 01 01 04 03 Will 03 04 00 03 04 07 00 01 00 07 04 Vasques 03 01 00 03 04 07 00 01 00 07 07