在 php 中使用 for 循环迭代 ol 标签内的 li 标签时,ol 标签不起作用

ol tag doesn't work while iterating li tag inside ol tag using for loop in php

我在 ol 标签内使用 for 循环迭代 li 标签,但没有显示 li 标签的有序列表编号

这是我的代码:

 <ol style="word-wrap:break-word;">
 <?php    
    for ($i = 0; $i < $length; $i++) {                                                                          
        echo '<li style="margin-left:0px;">'.$TnC1[$i].'</li>';                                             
       }
  ?>
</ol>

这是结果:

去掉for循环中不需要的,(逗号),同时加上结束标签''.

echo '<ol style="word-wrap:break-word;">';
for ($i = 0; $i < $length; $i++) { 

    echo '<li style="margin-left:0px;">'.$TnC1[$i].'</li>'; 

}
echo '</ol>'

您可以尝试以下代码片段。

<ol style="word-wrap:break-word;">
 <?php    
    //Start the counter value from 1 instead of 0
    for ($i = 1; $i <= $length; $i++) 
    { 
     //Print the counter value                                                                         
     echo $i.".".$TnC1[$i];                                             
    }
  ?>
</ol>