我正在尝试输出一个表,该表一次比较两个元素,每行末尾有一个单选按钮。我创建了一个遍历整个表的循环,并在内循环完成后跳转到下一个'表'。以及比较元素的内环。我遇到的问题是,如果在前一组中比较了两个元素,则不应在任何其他集合中重复。请参阅我下面的图片。
我尝试了不同的方法,但这是我的代码:
for ($i=0; $i < (sizeOf ($myArray)); $i++){ //loop through the whole table body
$currentObs = $myArray[$i]['ObstacleDescription']; //set pointer to my current obstacle value
$x = 0;
for ($j=1; $j <= (sizeOf($myArray)-1); $j++){ //loop through the inner table
$next = $myArray[$j]['ObstacleDescription'];
$or = " or ";
if (!($currentObs == $next)){
?>
<tr id="<?php echo $myArray[$i]['ComplianceID']; ?>">
<td valign='center'> <?php echo $x+1; ?> </td>
<?php $x++; ?>
<td>
<?php echo
"<input type='radio' name='op[$j]' value='0' class='myradio'>"." ".$currentObs
?>
</td>
<td><?php echo
$or." "."<input type='radio' name='op[$j]' value='1' class='myradio'>"." ".$next;
?>
</td>
<td><small>
<?php echo " 1 "."<input type='radio' name='Intense[$j]' value='1' class='myradio'>"; ?>
</small></td>
<td><small>
<?php echo
" 2 "."<input type='radio' name='Intense[$j]' value='2' class='myradio'>".
" 3 "."<input type='radio' name='Intense[$j]' value='3' class='myradio'>".
" 4 "."<input type='radio' name='Intense[$j]' value='4' class='myradio'>".
" 5 "."<input type='radio' name='Intense[$j]' value='5' class='myradio'>".
" 6 "."<input type='radio' name='Intense[$j]' value='6' class='myradio'>".
" 7 "."<input type='radio' name='Intense[$j]' value='7' class='myradio'>".
" 8 "."<input type='radio' name='Intense[$j]' value='8' class='myradio'>".
" 9 "."<input type='radio' name='Intense[$j]' value='9' class='myradio'>";
?>
</small></td>
<?php }
}
echo "<tr><td colspan='5'><hr style='border:0; height:0px' /></td></tr>";
echo "<tr><td colspan='5'><hr style='border:0; height:0px' /></td></tr>";
}
echo "</tr>";
?>
但这是我想要实现的目标:
答案 0 :(得分:1)
尝试改变内循环的条件,如下所示
for ($j=$i+1; $j <= (sizeOf($myArray)); $j++){