动态td foreach循环

I want to display a PHP array as table in which 8 tds in a tr, but I have no idea how to limit the td in inner loop.

 <?php
    $i=0;
    $related = array('1','2','3','4','5','6','7','8','9','10');
    for($i=0;$i<count($related);$i++){
        echo "<tr>";
        for($j=0;$j<8;$j++){
            echo "<td>".$related[$j]."</td>";
            $i++;   
        }
        echo $i;
        echo "</tr>";   
    }
?>

Yes finally i figure it out,

<?php
        $data = range(1, 20);
        for($i = 0; $i < count($data);)
        {
        echo "<tr>
";
        for($j = 0; $i < count($data) && $j < 8; $i++, $j++) {
        echo "\t<td>$data[$i]</td>
";
        }
        for(; $j < 8; $j++) {

        }
        echo "</tr>
";
        }
        ?>
<?php
    // your array
    $related = array('1','2','3','4','5','6','7','8','9','10');
    for($i=0;$i<count($related);$i++){
    $row = "";
    $row = "<tr>";
        for($j=0;$j<8;$j++){
        $row .= "<td>".$related[$j]."</td>";
    }
    $row .= "</tr>";
    echo $row;
}
?>

try this code